Adding Contact item in a STA thread.ContactItem and Redemption::IMessageItem::Save

S

Semut

Hello,


Firstly, I spawn a thread, and then I unmarshal what was passed in, which is
a MAPIFolder.
And then, I add an Outlook Contact Item. (assuming the MAPIFolder passed in
is a Contact folder)
The problem is that there is item added but the item is blank. I have put in
subject, title and last name but all these are not saved.

Why is it that the Outlook::_ContactItem::Save() not working?

I even tested this with Redemption::IMessageItem::Save. (I am using
GetItemFromID to obtain the MessageItem)

Same thing happen. In fact, redemption will crash at the Save function call.

Any reason why it can't be saved?????

Help.



Code snippet below

void threadFunc()
{
::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

LPDISPATCH lpMAPIFolder;
//unmarshalling of MAPIFolder.
LPSTREAM pData = g_Data;

if (pData )
{
::CoGetInterfaceAndReleaseStream
(
pIStreamForMAPI,
__uuidof(Outlook::MAPIFolderPtr),
(void**)&lpMAPIFolder
);


CComQIPtr<Outlook::MAPIFolder> spMAPIFolder(lpMAPIFolder);
CComPtr<Outlook::_Items> spItemsGet;
spMAPIFolder->get_Items(&spItemsGet);



CComPtr< IDispatch > spSingleItem;


spItemsGet->Add(CComVariant(Outlook::blush:lContactItem), &spSingleItem);
ATLASSERT(spSingleItem);


CComQIPtr<Outlook::_ContactItem> spContactItem(spSingleItem);

if(spContactItem == NULL)
return;

spContactItem->put_Subject(T2W("hello"));
spContactItem->put_LastName(T2W("last name"));
spContactItem->put_Title(T2W("hello2"));

spContactItem->Save();

lpMAPIFolder->Release();
::CoUninitialize();


}



}
 
D

Dmitry Streblechenko

Both OOM and Redemption are apartment threaded; all calls will be forwarded
to the main UI thread anyway. Why use a separate thread?

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

Semut

ok, more input to the problem.

I notice that the MAPIFolder that I marshal in not just have problem in
calling IMessageItem::Save or OOM Item::Save(). It also failed in adding
hidden messages (redemption).

Other than that, I can create subfolders, delete items, add item (blank) for
that MAPIFolder .

By the way, the child MAPIFolder(s) of the MAPIFolder that I marshal into
the STA thread, do not have problem on the IMessageItem::Save or OOM
Item::Save() thou. Looks like it is only specific to the MAPIFolder that I
marshalled in.


What could be the cause??


anyone care to help me out here.

thanks.
 
S

Semut

the code was fine in main thread (the Outlook itself)

problem only occur when i run it in STA thread.
 
S

Semut

After further study. I notice that it will only happen if I am trying to add
item to the MAPIFolder that I am currently viewing in the Outlook.
 

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