Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Outlook AddIn VC++
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.
Posted 6-Sep-12 2:15am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I wonder how you solve the problem? I met it recently.
Is it a bug?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Oh, I've found a way to figure it out!!
Just Remove : CComQIPtr spAttachment;
into for loop.
 
I think method "Item" refuse to overwrite spAttachment when he found it's not NULL
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 555
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 17 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100