Unhandled Exception while accessing the MAPIOBJECT in OnItemSend

  • Thread starter Thread starter Stefan Richter via OfficeKB.com
  • Start date Start date
S

Stefan Richter via OfficeKB.com

I tried to get access to the MAPIOBJECT of a MailItem. But everytime I call
QueryInterface() from the MAPIOBJECT I got the following exception:
Unhandled Exception in OUTLOOK.EXE (EXSEC32.DLL): 0xC0000005: Access
Violation

Stefan


Short snippet of code:

#include "stdafx.h"

#define INITGUID
#include <objbase.h>

#define USES_IID_IMessage
#include <mapix.h>
#include <mapitags.h>
#include <mapidefs.h>
#include <mapiutil.h>
#include <mapiguid.h>

#include "OutlookAddin.h"
#include "Addin.h"

....

void __stdcall CAddin::OnItemSend(IDispatch* Ctrl,VARIANT_BOOL *
CancelDefault)
{
HRESULT hr;
Outlook::_MailItemPtr MailItem;
IMessage *pMsg = NULL;
IUnknown *pUnk = NULL;

Ctrl->QueryInterface(Outlook::IID__MailItem, (void**)&MailItem);
MailItem->get_MAPIOBJECT(&pUnk);
hr = pUnk->QueryInterface((IID_IMessage), (void**)pMsg); // This call ends
everytime in an exception.
....
 
I am not using VC++, but don't you need to pass the address of the pMsg
variable (& operator)?
QueryInterface((IID_IMessage), (void**)&pMsg);

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top