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
 
Joined
Sep 15, 2009
Messages
2
Reaction score
0
error! while move....but succeeded to move

hi! i'm testing an addin on different machines, and on some machines it successfully moves the item and give me back the moved item, but on some machines it "MOVES" the item but reuturn nothing as new item and hr is also not S_OK, but diff on diff machines....so how do i get to know that move failed...although it did moved the item in actual but now i didnt have anything to get the new item id to play with the moved item......
anyone have any idea???


thanks in advance...
 

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