getting property from MAPIOBJECT

Y

yg

HI, I am building a COM Addin for Outlook 2000+ using VC++ 6.0
In my Event Handler - OnItemSend, I am trying to get the Mapi object
pointer so that I can get some properties from it like TextBody or any
other
available property. But the proble is that whenever I am calling a
method, I get a memoty violation failure. Below is my code. Can anyone
help me figure out what I am doing wrong. Thanks alot.


void __stdcall CAddin::OnItemSend(IDispatchPtr pDisp,VARIANT_BOOL
*pCancel)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HRESULT hr = S_OK;

CComQIPtr<Outlook::_MailItem> spMail(pDisp);
CComQIPtr<Outlook::Recipients> spRecipients;
CComQIPtr<Outlook::Recipient> spRecipient;
CComQIPtr<Outlook::Attachments> spAttachments;
CComQIPtr<Outlook::Attachment> spAttachment;

IMessage* pMsg = NULL;
IBodyPart* pBp = NULL;
IConfiguration* pConfig = NULL;
Fields* pFlds = NULL;
Field* pFld = NULL;
_Stream* pStm = NULL;
IUnknown* pUnk = NULL;

spMail->get_MAPIOBJECT(&pUnk);
hr = pUnk->QueryInterface(__uuidof(IMessage), (void**) pMsg);

..
..
..
..
..
..
}

But the pMsg pointer is allways NULL and I get a negative hr value
back.

if I try it like this:

spMail->get_MAPIOBJECT(&pUnk);
pMsg = (IMessage*) pUnk;
pMsg->get_BodyText(&bsBodyText)

then I get a memory viloattion error.

So how do I get a Mapi object pointer inside the OnItemSend event
handler ?

thanks !
 
D

Dmitry Streblechenko \(MVP\)

Where does the definition of IMessage come from? Note that it must be the
Extended MAPI version of IMessage (defined in MAPIDefs.h), not CDOSYS.

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

yg

Dmitry Streblechenko \(MVP\) said:
Where does the definition of IMessage come from? Note that it must be the
Extended MAPI version of IMessage (defined in MAPIDefs.h), not CDOSYS.

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


Hi, so should I include <mapidefs.h> instead of #immport <cdosys.dll>
if I do that, my code does not compile. If I leave both in, I get
redefinition error.
 
D

Dmitry Streblechenko \(MVP\)

What do you mean by "it does not compile"? What is the error?
Yes, you need to include MAPIDefs.h, you must also define USES IID_IMessage:

#define INITGUID
#include <objbase.h>

#define USES_IID_IMessage

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


also use IID_IMessage instead of (__uuidof(IMessage)

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

yg

Hi, so should I include <mapidefs.h> instead of #immport <cdosys.dll>
if I do that, my code does not compile. If I leave both in, I get
redefinition error.

Hi Dmitry , here is what I want to do:
In my event handler 'OnItemSend' I want to get the entire message
going out
including headers. In an MSDN example I saw that you can get the
Stream from an Imessage pointer like this:

IMessage* pMsg = NULL;
IBodyPart* pBp = NULL;
IConfiguration* pConfig = NULL;
Fields* pFlds = NULL;
Field* pFld = NULL;
_Stream* pStm = NULL;

hr=CoCreateInstance(
__uuidof(Message),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IMessage),
(void**)&pMsg);

pMsg->put_To(_bstr_t("\"Xyz Xyz\" <[email protected]>"));
pMsg->put_From(_bstr_t("\"Xyz Xyz\" <[email protected]>"));
pMsg->put_Subject(_bstr_t("Test"));

pMsg->AddAttachment(L"c:\\document.doc",L"",L"",&pBp);
pBp->put_ContentMediaType(L"application/msword");
pBp->Release();
pBp = NULL;

pMsg->GetStream(&pStm);
hr = pStm->SaveToFile(L"c:\\savemymessage.eml",adSaveCreateOverWrite);

..
..
..

So from this code snippete I can get the Stream and save it to a file.
But how can I simultae this in my 'OnItemSend' event handler ? How can
I get the message stream there ?

thanks you very much.
 
D

Dmitry Streblechenko \(MVP\)

EML (or RFC822) format is not native to Extended MAPI, you would need to
either create the EML file property by property or use a third party library
(e.g. Redemption, url below, see SafeMailItem.SaveAs(path, olRFC822)).
This will not be the exact RFC822 message about to be sent - the real
conversion will be handled by the SMTP transport provider (if that is what
will be used - in case of two Exchange mailboxes the conversion never takes
place).

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

yg

Dmitry Streblechenko \(MVP\) said:
EML (or RFC822) format is not native to Extended MAPI, you would need to
either create the EML file property by property or use a third party library
(e.g. Redemption, url below, see SafeMailItem.SaveAs(path, olRFC822)).
This will not be the exact RFC822 message about to be sent - the real
conversion will be handled by the SMTP transport provider (if that is what
will be used - in case of two Exchange mailboxes the conversion never takes
place).

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

Hi Dmitry, so if I add the follwoing to my main header file:

#include <objbase.h>
#include <mapix.h>
#include <mapitags.h>
#include <mapidefs.h>
#include <mapiutil.h>
#include <mapiguid.h>

#define INITGUID
#define USES_IID_IMessage

on top of what's allready included there:

#import <cdosys.dll> no_namespace raw_interfaces_only
#import "c:\program files\common files\system\ado\msado15.dll"
no_namespace raw_interfaces_only
#include "cdosysstr.h"
#include "cdosyserr.h"

and then I try to rebuild the addon, I get the follwoing compile time
errors:

cdosys.tlh(416) : error C2011: 'IMessage' : 'struct' type redefinition

which happens because I am inlduing CDOSYS I assume, but if I don't
include it
I can not work with Interfaces like:

IBodyPart
IConfiguration

which I need inoreder to build an email message and get the MIME
entity.

any suggestions ?

thanks alot.


thanks.
 
D

Dmitry Streblechenko \(MVP\)

You should not be referencing CDOSYS at all. IBodyPart and IConfiguration
have nothing to do with anything related to MAPI or Outlook.

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

yg

Dmitry Streblechenko \(MVP\) said:
You should not be referencing CDOSYS at all. IBodyPart and IConfiguration
have nothing to do with anything related to MAPI or Outlook.

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

thanks Dmitry, can you tell me the name of the Interface I need to
query for
the redemption COM object. I am using smart pointers (with VC++) so I
am imporing the DLL.
#import "c:\\winnt\systemre32\\redemption.dll"


thanks ...
 

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