Unhandled Exception while accessing the MAPIOBJECT in OnItemSend

  • Thread starter Stefan Richter via OfficeKB.com
  • 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.
....
 
D

Dmitry Streblechenko

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top