Using MailItem::Move in C++

  • Thread starter Martynas Kunigelis
  • Start date
M

Martynas Kunigelis

Hi everyone,

consider this C++ code (Outlook typelib imported with raw_interfaces_only):

-----------------------------------------------------

Outlook::MAPIFolder* pTargetFolder;
Outlook::_MailItem* pMailItem;

....
//
// pTargetFolder and pMailItem are correctly initialized here
//
....

IDispatch* pReturnedItem;

HRESULT hr = pMailItem->Move(pTargetFolder, &pReturnedItem);

-----------------------------------------------------

As far as I understand, pReturnedItem points to a new object that represents
the moved item. I further call QueryInterface() on it to obtain a pointer to
Outlook::_MailItem.

The question is: should I call Release() on the original pMailItem after
Move()?

I would think so, but I'm chasing a weird bug that makes Outlook XP crash on
exit, in InterlockedDecrement in kernel32.dll, called from ole32.dll. I'm
suspicious that InterlockedDecrement is used to decrement the reference
count on a COM object, and that something is getting released one time too
many in my code.

Thanks in advance,
Martynas
 
D

Dmitry Streblechenko

Yes, after calling Move() the original message becomes invalid and must be
immediately released.


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