To implement a transport provider, you must initialize the transport provider by using the XPProviderInit function as an entry point. Once the transport provider's DLL is initialized, the IXPProvider::TransportLogon function allows MAPI to log on to the transport provider.
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 by 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.
After you have initialized a transport provider, the next step is to set up the types of addresses the transport provider will accept and notify MAPI that the transport provider is ready for processing. For more information, see Setting Up a Transport Provider.
Initialization Routine
All transport providers must implement XPProviderInit as an entry point to initialize the provider's DLL. XPProviderInit checks to see if the version number of the service provider interface, ulMAPIVer, is compatible with the current version number, CURRENT_SPI_VERSION. The function creates a new instance of the CXPProvider class and returns it in the lppXPProvider parameter.
XPProviderInit() Example
STDINITMETHODIMP XPProviderInit(
HINSTANCE hInstance,
LPMALLOC /*lpMalloc*/,
LPALLOCATEBUFFER lpAllocateBuffer,
LPALLOCATEMORE lpAllocateMore,
LPFREEBUFFER lpFreeBuffer,
ULONG /*ulFlags*/,
ULONG ulMAPIVer,
ULONG FAR * lpulProviderVer,
LPXPPROVIDER FAR * lppXPProvider)
{
Log(true, _T("XPProviderInit function called\n"));
if (!hInstance || !lpAllocateBuffer || !lpAllocateMore || !lpFreeBuffer
|| !lpulProviderVer || !lppXPProvider)
return MAPI_E_INVALID_PARAMETER;
if (ulMAPIVer < CURRENT_SPI_VERSION)
{
Log(true, _T("XPProviderInit: Invalid version passed in ulMAPIVer: %d\n"),
ulMAPIVer);
return MAPI_E_VERSION;
}
CXPProvider* pProvider =NULL;
pProvider = new CXPProvider(hInstance);
if (!pProvider)
{
Log(true, _T("XPProviderInit: failed to create new CXPProvider\n"));
return MAPI_E_NOT_ENOUGH_MEMORY;
}
*lpulProviderVer = CURRENT_SPI_VERSION;
*lppXPProvider = (LPXPPROVIDER)pProvider;
return S_OK;
}
Logon Routine
The last step in initializing the transport provider is to call IXPProvider::TransportLogon so that MAPI can log on to the transport provider. The function calls the OpenProfileSection method to get the profile properties for the user. Then the TransportLogon function evaluates the input flags from the lpulFlags parameter to set the status for the logon session, and sets the appropriate output flags. The new logon object is returned in the lppXPLogon parameter.