none
Access violation exception in code sample outlook 2013 profile RRS feed

  • Question

  • I tried to create a project for the code sample at

    https://blogs.msdn.microsoft.com/dvespa/2017/06/19/create-outlook-2013-profile-mapi-http/

    I use the Visual Studio 2017 compiler patched at today.

    I get

    Unhandled exception at 0x011B1676 in CreateProfile.exe: 0xC0000005: Access violation reading location 0x8800041C.

    at this line "& lpStoreProfSection)) || "

    See below

    line 214:     if (FAILED(hRes = GetStoreProvidersSection(
            lpSvcAdmin,
            (LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb,
            & lpStoreProfSection)) ||
            (lpStoreProfSection == nullptr))
        {
            cout << "Error attempting to get the Store Providers Profile Section.";
            goto error;
        }


    • Edited by tionescu Friday, June 21, 2019 6:07 AM
    Friday, June 21, 2019 6:06 AM

All replies

  • Hello,

    First of all, you need to make sure you create an unmanaged project in Visual Studio. Second, I'd suggest checking the target platform of your application - it should be set to the x86 platform.

    Did you try to run the code under the debugger and check actual values that are passed and returned to/from methods? Is everything ok in that case?


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Friday, June 21, 2019 6:31 AM
  • Hi Eugene,

    I built a release x32 project using below settings. it runs on

    OS Name:                   Microsoft Windows Server 2016 Standard
    OS Version:                10.0.14393 N/A Build 14393


    • Edited by tionescu Friday, June 21, 2019 6:49 AM
    Friday, June 21, 2019 6:49 AM
  • ok, i changed the project to be CLR Console Application using dot.net 4.6.1 and i got it compiled and running not crashing, but it fails with error:

    C:\code\Visual Studio 2017\Projects\CreateProfileCLRApp\Release>CreateProfileCLRApp.exe
    Error initializing MAPI. hRes = 0x80010106

    I have 32-bit Outlook 2013 installed.

    What do I miss now?


    • Edited by tionescu Friday, June 21, 2019 7:06 AM
    Friday, June 21, 2019 7:05 AM
  • I initialized the MAPI as follows

        // Initialize MAPI.
        MAPIINIT_0 MAPIINIT = { 0, MAPI_MULTITHREAD_NOTIFICATIONS | MAPI_NO_COINIT };

        if (FAILED(hRes = MAPIInitialize(&MAPIINIT)))

    and it passed the "Error initializing MAPI. hRes = 0x80010106"

    But now i got to the same fatidic line. See below


    • Edited by tionescu Friday, June 21, 2019 7:54 AM
    Friday, June 21, 2019 7:38 AM
  • I initialized the MAPI as follows

        // Initialize MAPI.
        MAPIINIT_0 MAPIINIT = { 0, MAPI_MULTITHREAD_NOTIFICATIONS | MAPI_NO_COINIT };

        if (FAILED(hRes = MAPIInitialize(&MAPIINIT)))

    and it passed the "Error initializing MAPI. hRes = 0x80010106"


    In unmanaged code (not a CLR project) you should initialize MAPI in the manner shown in the blog sample code --

    if (FAILED(hRes = MAPIInitialize(NULL)))
    {
    cout << "Error initializing MAPI.";
    goto error;
    }


    • Edited by RLWA32 Friday, June 21, 2019 9:30 AM
    Friday, June 21, 2019 9:29 AM
  • @all,

    i have both projects (Windows Console Application and CLR Console App) and they both crash on GetStoreProvidersSection because you cannot call null point-to-reference.

    Any idea how to change the whole sample to work?

    ```

    int _tmain(int argc, _TCHAR* argv[])
    {
    ..

       LPPROFSECT lpStoreProfSection = nullptr;
    ..

    if (FAILED(hRes = GetStoreProvidersSection(
            lpSvcAdmin,
            (LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb,
            &lpStoreProfSection)) ||
            (lpStoreProfSection == nullptr))

    {}

    ```

    Friday, June 21, 2019 10:44 AM
  • @all,

    i have both projects (Windows Console Application and CLR Console App) and they both crash on GetStoreProvidersSection because you cannot call null point-to-reference.

    Any idea how to change the whole sample to work?

    ```

    int _tmain(int argc, _TCHAR* argv[])
    {
    ..

       LPPROFSECT lpStoreProfSection = nullptr;
    ..

    if (FAILED(hRes = GetStoreProvidersSection(
            lpSvcAdmin,
            (LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb,
            &lpStoreProfSection)) ||
            (lpStoreProfSection == nullptr))

    {}

    ```

    Are you saying that lpSvcAdmin is NULL?  lpSvcRows is NULL?

    Did this code from the sample succeed but pointers remained NULL?

    // Get an IMsgServiceAdmin interface off of the IProfAdmin interface.
    if (FAILED(hRes = lpProfAdmin->AdminServices((LPTSTR)ProfileName.c_str(), // Profile that we want to modify.
    nullptr, // Password for that profile.
    0, // Handle to parent window.
    0, // Flags.
    &lpSvcAdmin))) // Pointer to new IMsgServiceAdmin.
    {
    cout << "Error getting IMsgServiceAdmin interface.";
    goto error;
    }
    if (FAILED(hRes = HrQueryAllRows(lpMsgSvcTable,
    (LPSPropTagArray)&sptCols,
    &sres,
    NULL,
    0,
    &lpSvcRows)))
    {
    cout << "Error querying table for new message service.";
    goto error;
    }

    You should step through the executing code line by line in the debugger to identify the exact source of the problem.



    • Edited by RLWA32 Friday, June 21, 2019 11:25 AM
    Friday, June 21, 2019 11:14 AM
  • Also I'd suggest playing with MFCMAPI to understand how the project should be configured and works. See MFCMAPI demonstrates MAPI client code for more information.

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Saturday, June 22, 2019 8:23 PM
  • OK. Let's debug it step by step running debug x32 build.

    Monday, July 1, 2019 6:54 AM
  • OK.The following throws the exception.

    (LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb


    • Edited by tionescu Monday, July 1, 2019 8:53 AM
    Monday, July 1, 2019 8:52 AM
  • what is that MapiSvc.inf file?

    i only have

    C:\Windows\WinSxS\wow64_microsoft-windows-fax-mapi_31bf3856ad364e35_10.0.14393.0_none_87691a48c2fb078d\mapisvc.inf

    Monday, July 1, 2019 9:07 AM
  • From this image and the one above it appears that the code is working with bad data. 

    For example, look at the numeric values for cValues.  Those counts and the other visible members of the structures look like bad data to me.  The lpSvcRows->aRow->lpProps pointer is invalid.

    And I would suggest testing with unmanaged code.

    Monday, July 1, 2019 9:50 AM
  • I see it works with invalid data. The sample code talks of some mapisvc.inf file

    What it should contain? I don't find it in c:\windows\syswow64 

    Monday, July 1, 2019 10:33 AM
  • Well, in the past when I installed the msi version of Office 2013 no additional steps needed to be taken with respect to the mapisvc.inf file.

    Are you using an msi version or a click to run version?

    Monday, July 1, 2019 1:14 PM
  • Have you started Outlook 2013 and let it create a profile?
    Monday, July 1, 2019 2:41 PM
  • yes, i did it. but i see server not resolved

    are there any clean up instructions for outlook 2013 and 2016?

    Monday, July 1, 2019 3:01 PM
  • After reboot it works again

    I tried to install that certificate in the system keystore but it comes every time. Any idea?

    Monday, July 1, 2019 3:11 PM