Shutting Down a Transport Provider

Shutting Down a Transport Provider

After you are done using a transport provider to send and receive messages, you must properly shut down and log off the transport provider. For more information about sending and receiving messages by using the transport provider, see Sending Messages by Using a Transport Provider and Receiving Messages by Using a Transport Provider.

To shut down the transport provider you must call the IXPProvider::Shutdown function. This function closes down the transport provider and calls the IXPLogon::TransportLogoff function to terminate the transport provider session for a particular user.

In this topic, these functions are demonstrated by using code examples from the MRXP Sample Transport Provider. The MRXP Sample Transport Provider implements a shared network file system transport provider using a UNC share or a local folder. For more information about downloading and installing the MRXP Sample Transport Provider, see Installing the Sample Transport Provider.

Shut Down Routine

MAPI calls the IXPProvider::Shutdown function just before it releases the transport provider so that the transport provider can close down. The function goes through a linked list of IXPLogon objects and calls the IXPLogon::TransportLogoff function to release each object.

CXPProvider::Shutdown() Example

  STDMETHODIMP CXPProvider::Shutdown(ULONG FAR* /*lpulFlags*/)
{
    Log(true, _T("CXPProvider::Shutdown function called\n"));
    HRESULT hRes = S_OK;
EnterCriticalSection(&m_csObj);
CXPLogon* pCurrent = m_pLogonList;
while (pCurrent)
{
    CXPLogon* pNext = pCurrent->GetNextLogon();
    hRes = pCurrent->TransportLogoff(0);
    if (FAILED(hRes))
        Log(true, _T("CXPProvider::Shutdown: TransportLogoff returned an error: "
            + "0x%08X\n"), hRes);
    pCurrent->Release();
    pCurrent = pNext;
}
LeaveCriticalSection(&m_csObj);

return S_OK;

}

Transport Logoff Routine

The IXPLogon::TransportLogoff function terminates a transport provider session for a particular user. The function removes the current instance from the linked list of IXPLogon objects.

CXPLogon::TransportLogoff

  STDMETHODIMP CXPLogon::TransportLogoff(ULONG /*ulFlags*/)
{
    Log(true, _T("CXPLogon::TransportLogoff function called\n"));
    HRESULT hRes = S_OK;
// Remove this session from the linked list
CXPLogon* pPrev = NULL;
CXPLogon* pCur = NULL;

EnterCriticalSection(m_pProvider->GetCS());
pCur = m_pProvider->GetLogonList();
while (pCur)
{
    if (pCur == this)
    {
        if (pPrev == NULL)
            m_pProvider->SetLogonList(pCur->GetNextLogon());
        else
            pPrev->SetNextLogon(pCur->GetNextLogon());
        break;
    }
    pPrev = pCur;
    pCur = pCur->GetNextLogon();
}
LeaveCriticalSection(m_pProvider->GetCS());

return hRes;

}

See Also

About the Sample Transport Provider

Installing the Sample Transport Provider

Initializing a Transport Provider

Setting Up a Transport Provider

Sending Messages by Using a Transport Provider

Receiving Messages by Using a Transport Provider