Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
Hi,


I m trying to develop outlook plugin using ATL/COM in c++. I want to get the MailItem methods to access the outlook mail so that i can get the desired results like TO, CC, BCC, Subject, Body and attachments.....till now i have got everything accept attachments here is my code for getting attachments


XML
CComPtr<Outlook::_MailItem> MailPtr;
CComQIPtr<Outlook::Attachments> spAttachments;
CComQIPtr<Outlook::Attachment> spAttachment;

long count;

C#
MailPtr->get_Attachments (&spAttachments);

spAttachments->get_Count (&count);


VB
for (;count--; )
{
    VARIANT index;
    index.iVal = 1; // value
    index.vt = VT_I2; // type of variant = integer
    BSTR StoragePtr;

    spAttachments->Item (index, &spAttachment);

    spAttachment->get_FileName (&StoragePtr);
    MessageBoxW (NULL, (LPCWSTR)StoragePtr, L"Attached File Name", MB_OK);

}

The above code works fine for only one attachment but if there are more than one attachments it is getting crash when it comes for the second time in the for loop here at this line it is getting crash


spAttachments->Item (index, &spAttachment);

i m not able to get the file name of the second attachment so please anyone help me to this problem.

Thanks in advance.
Posted

I wonder how you solve the problem? I met it recently.
Is it a bug?
 
Share this answer
 
Oh, I've found a way to figure it out!!
Just Remove : CComQIPtr<outlook::attachment xmlns:outlook="#unknown"> spAttachment;
into for loop.

I think method "Item" refuse to overwrite spAttachment when he found it's not NULL
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900