2014-10-27 28 views
0

我无法获取特定的Outlook(2013)电子邮件附件。我正在开发一个小项目,学习使用C++的MS Office Automation,并且测试Outlook自动化。在部分我想下载一个特定的电子邮件附件,但我无法访问该项目。例如,如果我在我的收件箱中收到带有4个附件的电子邮件,我想要第二个附件。 我试图与此代码,但HRESULT从AutoWrap返回的值()方法是总是无效:获取特定的Outlook附件(OLE自动化C++)

VARIANT result; 
VariantInit(&result); 

CComPtr<IDispatch> pAttachments; // email attachments 
HRESULT hRes = AutoWrap(DISPATCH_PROPERTYGET, &result, pOfficeItem, L"Attachments", 0); 
if (!result.pdispVal || FAILED(hRes)) return EditorError; // EditorError is an Enum 

pAttachments = result.pdispVal; 

VariantInit(&result); 
hRes = AutoWrap(DISPATCH_PROPERTYGET, &result, pAttachments, L"Count", 0); 
if (FAILED(hRes)) return EditorError; 

int aNumber = result.iVal; // it works, if i have an email with 4 attachments then aNumber is 4 
if(aNumber > 0){ 
    VARIANT attachmentIndex; 
    attachmentIndex.vt = VT_I4; 
    attachmentIndex.llVal = 0; // I want the 1st attachment 

    VariantInit(&result); 
    CComPtr<IDispatch> pAttachmentItem; 

hRes = AutoWrap(DISPATCH_PROPERTYGET, &result, pAttachments, L"Item", 1, attachmentIndex); 
    if (FAILED(hRes)) return EditorError; // here it returns EditorError 
} 
... DO SOMETHING ... 

其中AutoWrap()是由MS以与MS的应用进行交互推荐的方法(http://www.codeproject.com/Articles/34998/MS-Office-OLE-Automation-Using-C) 。

回答

0

备注:

索引属性为仅在当前会话期间有效,并且可以更改为对象添加和从集合中删除。 集合中的第一个对象的索引值为1.