Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Add-Ins / February 2004

Tip: Looking for answers? Try searching our database.

getting property from MAPIOBJECT

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
yg - 02 Feb 2004 23:52 GMT
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 !
Dmitry Streblechenko \(MVP\) - 03 Feb 2004 00:21 GMT
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, 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
[quoted text clipped - 50 lines]
>
> thanks !
yg - 03 Feb 2004 15:38 GMT
> 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.
[quoted text clipped - 58 lines]
> >
> > thanks !

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.
Dmitry Streblechenko \(MVP\) - 03 Feb 2004 17:30 GMT
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

> > 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.
[quoted text clipped - 62 lines]
> if I do that, my code does not compile. If I leave both in, I get
> redefinition error.
yg - 03 Feb 2004 21:07 GMT
> > 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.
[quoted text clipped - 62 lines]
> 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\" <xyz@zxy.com>"));
pMsg->put_From(_bstr_t("\"Xyz Xyz\" <xyz@zxy.com>"));
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.
Dmitry Streblechenko \(MVP\) - 03 Feb 2004 23:13 GMT
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

> > > 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.
[quoted text clipped - 104 lines]
>
> thanks you very much.
yg - 05 Feb 2004 00:40 GMT
> 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
[quoted text clipped - 124 lines]
> >
> > thanks you very much.

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.
Dmitry Streblechenko \(MVP\) - 05 Feb 2004 05:25 GMT
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

> > 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
[quoted text clipped - 165 lines]
>
> thanks.
yg - 06 Feb 2004 18:15 GMT
> You should not be referencing CDOSYS at all. IBodyPart and IConfiguration
> have nothing to do with anything related to MAPI or Outlook.
[quoted text clipped - 187 lines]
> >
> > thanks.

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 ...
Dmitry Streblechenko \(MVP\) - 06 Feb 2004 20:47 GMT
SafeMailItem. What are the properties that you are trying to read?

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

> You should not be referencing CDOSYS at all. IBodyPart and IConfiguration
> have nothing to do with anything related to MAPI or Outlook.
[quoted text clipped - 136 lines]
> > > > pMsg->GetStream(&pStm);
> > > > hr =
pStm->SaveToFile(L"c:\\savemymessage.eml",adSaveCreateOverWrite);

> > > > .
> > > > .
[quoted text clipped - 46 lines]
> >
> > thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.