Search code examples
c++visual-c++outlookmapi

MAPI Stub Library cannot initialize MAPI for Outlook 2016(64bit)


My computer is Windows 7(64bit), I then install Outlook 2016(64bit).

Then I follow the instructions in https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/how-to-link-to-mapi-functions?redirectedfrom=MSDN to use MAPIStubLibrary.

The version of MAPIStubLibrary I use is updated on 2018-02-26.

I include the MapiStubLibrary.cpp and StubUtils.cpp to my project directly. Then I call the following line to initialize MAPI:

if (MAPIInitialize(NULL) != S_OK)
  AfxMessageBox(_T("Initialize MAPI fails!"));

However, when invoke the above code, I will see a message box said "

Either there is no default mail client or the current mail client cannot fulfill the messaging request. Please run Microsoft Outlook and set it as the default mail client.

And the function MAPIInitialize(NULL) will return E_FAIL. But I have set Outlook 2016(64bit) as the default mail client.

I think maybe I need to update MAPIStubLibrary to its latest version, so I go to https://github.com/stephenegriffin/MAPIStubLibrary and then download the latest version.

Then copy all files under library folder to my project, including MapiStubLibrary.cpp, StubUtils.cpp and StubUtils.h.

Then I rebuild the project in VS2008. However, this time I get a lot of errors:

.\MAPIStubLibrary\MapiStubLibrary.cpp(1155) : error C2065: 'nullptr' : undeclared identifier
.\MAPIStubLibrary\StubUtils.cpp(44) : error C2039: 'function' : is not a member of 'std'
.\MAPIStubLibrary\StubUtils.cpp(44) : error C2143: syntax error : missing ';' before '<'
.\MAPIStubLibrary\StubUtils.cpp(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\MAPIStubLibrary\StubUtils.cpp(45) : error C2086: 'int mapistub::function' : redefinition
        .\MAPIStubLibrary\StubUtils.cpp(44) : see declaration of 'mapistub::function'
.\MAPIStubLibrary\StubUtils.cpp(49) : error C2065: 'logLoadMapiCallback' : undeclared identifier

Why?

Update:

I double check and confirm the Outlook is 64bit: enter image description here


Solution

  • That means Outlook is either not installed or that it has a different bitness. Check Outlook bitness in File | Office Outlook | About Outlook.