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
CComPtr<Outlook::_MailItem> MailPtr;
CComQIPtr<Outlook::Attachments> spAttachments;
CComQIPtr<Outlook::Attachment> spAttachment;
long count;
MailPtr->get_Attachments (&spAttachments);
spAttachments->get_Count (&count);
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.