How to: Link to MAPI Functions
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

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
  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;
      //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
    return (0);
© 2016 Microsoft