本文介绍了如何在Outlook上打开电子邮件正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让Outlook打开电子邮件正文。使用下面的代码,我设法将pDispatch作为_MailItem类型。问题是,当我试图获得电子邮件正文时失败:
Hi,
I would like to get Outlook opened email body. Using code below, I managed to get pDispatch as _MailItem type. The problem is, it fails when I tried to get email body:
hr = pMailItem->get_Body(&messageBody); //failed here
需要你们的建议。下面是我的代码片段:
Need suggestions from you guys. Below is snippet of my code:
case 0x0000fba7:
if(pDispParams->cArgs <= 0)
return E_INVALIDARG;
else
{
HRESULT hr;
IDispatch *pDispatch = pDispParams->rgvarg[0].pdispVal;
BSTR szName;
if(pDispatch)
{
LPTYPEINFO lpMyTypeInfo = NULL;
hr = pDispatch->GetTypeInfo(0,0,&lpMyTypeInfo);
if(lpMyTypeInfo != NULL)
hr = lpMyTypeInfo->GetDocumentation(MEMBERID_NIL,&szName,0,0,0);
}
if (0 != strcmp("_MailItem",(char *)(_bstr_t)szName)) //confirmed
break;
Outlook::_MailItemPtr pMailItem = NULL;
pDispatch->QueryInterface(__uuidof(_MailItemPtr), (void**)&pMailItem);
if (pMailItem)
{
BSTR messageBody;
hr = pMailItem->get_Body(&messageBody); //failed here
if(FAILED(hr))
{
//hr returned error code seems random everytime i debug
}
}
}
break;
推荐答案
IDispatch *pDispatch = pDispParams->rgvarg[0].pdispVal //can't use this
case 0x0000fba7:
if(pDispParams->cArgs <= 0)
return E_INVALIDARG;
else
{
Outlook::_ApplicationPtr spApp("Outlook.Application");
Outlook::_MailItemPtr spMailItem;
IDispatch *pDispatch;
HRESULT hr;
long lll;
variant_t vvv = 1;
if (NULL == spApp)
{
hr = spApp.CreateInstance("Outlook.Application");
}
if (spApp)
{
Outlook::_ExplorerPtr spExplorer;
hr = spApp->ActiveExplorer(&spExplorer);
if (spExplorer)
{
Outlook::SelectionPtr spSel;
hr = spExplorer->get_Selection(&spSel);
hr = spSel->get_Count(&lll);
if (spSel && lll == 1) // if only 1 selection
{
hr = spSel->Item(vvv, &pDispatch);
pDispatch->QueryInterface(__uuidof(_MailItemPtr), (void**)&spMailItem);
BSTR bbb;
hr = spMailItem->get_Body(&bbb); //get email body
}
}
}
}
break;
这篇关于如何在Outlook上打开电子邮件正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!