Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to: Link to MAPI Functions

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Previously, calling MAPI functions in a messaging application involved linking to the Mapi32.lib library. This includes routing MAPI calls to the Mapi32.dll OS component, which then forwards the calls to the default MAPI client implementation at runtime.

Because the default MAPI client now supports on-demand installation using Windows Installer (MSI), you can develop messaging applications directly on top of the implementation instead of going through Mapi32.lib. The following shows you how to call MAPI functions using explicit linking.

For more information about explicit linking, see Linking Explicitly.


To call MAPI APIs without the MAPI32.lib library

  1. In your program file, create a global array of function pointers for each MAPI API you are using.

    The following example illustrates this step.

    //Global MAPI function pointers
    LPMAPIINITIALIZE pfnMAPIInitialize = NULL;
    LPMAPIUNINITIALIZE pfnMAPIUninitialize = NULL;
    
  2. Create a function that initializes MAPI functions to link to the MAPI DLL (Mapi32.dll). In this function, do the following:

    1. Call the function FGetComponentPath to get the path and DLL name that implements the MAPI subsystem. For more information see How to: Choose a Specific Version of MAPI to Load.

    2. Load the DLL by calling the function LoadLibrary.

    3. Initialize the MAPI function pointer array by calling the function GetProcAddress.

    The following example illustrates the previous steps:

    void InitializeMapiFunctions()
    {
      //Get the DLL path and name of the actual MAPI implementation
      FGetComponentPath(g_szMapiComponentGUID, NULL, szMAPIDLL, MAX_PATH);
    
      //Load the DLL
      hMod = LoadLibrary(szMAPIDLL);
    
      //Initialize MAPI functions
      pfnMAPIInitialize = GetProcAddress(hMod, “MAPIInitialize”);
      pfnMAPIUninitialize = GetProcAddress(hMod, “MAPIUninitialize”);
    }
    
  3. Finally, call the function you created in step 2 in your messaging application before you make calls to MAPI APIs.

    Security noteSecurity Note

    You must uninitialize the MAPI subsystem before closing your application.

    The following example illustrates this step:

    int main()
    {
      HRESULT hr;
    
      InitializeMapiFunctions();
    
      //Initialize the MAPI subsystem
      hr = (*pfnMAPIInitialize)(NULL);
      if (hr!= S_OK)
      {
        //Handle the error case
      }
      //Here’s where you make calls to other MAPI APIs
    
      //Uninitialize the MAPI subsystem
      (*pfnMAPIUninitialize)();
    return (0);
    }
    
Show:
© 2014 Microsoft