C++ mapi outlook call to ResolveMessageClass fails randomly?

  c++, mapi, outlook

I am working on my outlook plugin using C++ MAPI.
On one particular button click I want to open New Mail window for which I am following below approach. But to my surprise, IMAPIFormMgr::ResolveMessageClass() function fails. That too randomly. At times it works fine and at other times it fails. Couldn’t figure out what could be the cause for the same.
Any pointer, idea?

My code flow is something like below
Note: It’s not full code, just little bit of overview.

I have printed all the variables and poiters in my log fine and non of them is NULL or garbage or like.

Still it fails at ResolveMessageClass() function only. That too strangely it fails randomly. many a time it works like champ and suddenly it shows some error in ResolveMessageClass()

Code

CComPtr<IMessage> mapiMessage;
hRes = spOutboxFolder->CreateMessage(&IID_IMessage, 0, &mapiMessage);

CComPtr<IMAPIFormInfo> pFormInfo;

std::wstring szMessageClass(L"IPM.Note");

hRes = pFormMgr->ResolveMessageClass(
     wstringTostring(szMessageClass).c_str(), // Message class is ALWAYS ANSI --> Never Unicode
    0,
    spOutboxFolder.get(),
    &pFormInfo);

CComPtr<IPersistMessage> pPersistMessage;

hRes = pFormMgr->CreateForm(NULL, 0L, pFormInfo, IID_IPersistMessage, (LPVOID*)&pPersistMessage);

ULONG_PTR ul = 0;

hRes = spSession->PrepareForm(NULL, mapiMessage, &ul);

hRes = spSession->ShowForm(
                            NULL, //(ULONG)parent->GetSafeHwnd(),
                            msgStore,
                            spInboxFolder.get(),
                            NULL,
                            ul,
                            NULL,
                            MAPI_POST_MESSAGE,
                            pPropsMsg[MSG_STATUS].Value.l,
                            pPropsMsg[MSG_FLAGS].Value.l,
                            pPropsMsg[MSG_ACCESS].Value.l,
                            pPropsMsg[MSG_CLASS].Value.lpszA);

Thanks in advance

Source: Windows Questions C++

LEAVE A COMMENT