我无法获得特定的Outlook(2013)电子邮件附件。我正在开展一个小项目,以便使用C ++了解MS Office Automation,并且我正在测试Outlook自动化。在部分我想下载一个特定的电子邮件附件,但我无法访问该项目。例如,如果我的收件箱中有一个包含4个附件的电子邮件,我想获得第二个附件。 我尝试使用此代码,但AutoWrap()方法的HRESULT返回值始终无效:
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 :(得分:0)
说明:
Index属性仅在当前会话期间有效,并且可以在向集合中添加和删除对象时进行更改。 集合中的第一个对象的索引值为1.