COM を使用して VSTO 2007 Outlook Addin を作成しています。Outlook からすべてのメールアイテムを読み取り、未配信のメール アイテムを未配信としてマーク (カテゴリ) します。
以下のコードを使用して、未配信のメール アイテムを未配信としてマークしています。読み取り色でマークされたコードがクラッシュすることがあります。問題を提案してください。
HRESULT hrGetSelectedItem;
LPDISPATCH spOlSelectedItem = NULL;
CComPtr<Outlook::_Explorer> spExplorer;
//Locating the selected item
CComPtr<Outlook::Selection> spOlSel;
if(m_spApp)
{
//Get the Currently Active Explorer on the top of Desktop
hrGetSelectedItem = m_spApp->ActiveExplorer(&spExplorer);
if(SUCCEEDED(hrGetSelectedItem))
{
hrGetSelectedItem = spExplorer->get_Selection(&spOlSel);
if(FAILED(hrGetSelectedItem))
{
MessageBox(NULL,GetStringFromTable(IDS_SELECTITEM),MSGBOX_HEADER, MB_OK|MB_ICONINFORMATION);
return ;
}
iMailIndex+=1;
VARIANT covIndex;
covIndex.vt = VT_I4;
covIndex.lVal = iMailIndex;
if(spOlSel)
{
hrGetSelectedItem = spOlSel->Item(covIndex,&spOlSelectedItem);
CComQIPtr <Outlook::_MailItem> spMailItem;
if(spOlSelectedItem)
{
hrGetSelectedItem = spOlSelectedItem->QueryInterface(&spMailItem);//Get The selected item
if(spMailItem)
{
spMailItem->put_Categories(L"Undelivered");
spMailItem->Save();
}
}
}
}
} LPDISPATCH spOlSelectedItem = NULL;
CComPtr<Outlook::_Explorer> spExplorer;
//Locating the selected item
CComPtr<Outlook::Selection> spOlSel;
if(m_spApp)
{
//Get the Currently Active Explorer on the top of Desktop
hrGetSelectedItem = m_spApp->ActiveExplorer(&spExplorer);
if(SUCCEEDED(hrGetSelectedItem))
{
hrGetSelectedItem = spExplorer->get_Selection(&spOlSel);
if(FAILED(hrGetSelectedItem))
{
MessageBox(NULL,GetStringFromTable(IDS_SELECTITEM),MSGBOX_HEADER, MB_OK|MB_ICONINFORMATION);
return ;
}
iMailIndex+=1;
VARIANT covIndex;
covIndex.vt = VT_I4;
covIndex.lVal = iMailIndex;
if(spOlSel)
{
hrGetSelectedItem = spOlSel->Item(covIndex,&spOlSelectedItem);
CComQIPtr <Outlook::_MailItem> spMailItem;
if(spOlSelectedItem)
{
hrGetSelectedItem = spOlSelectedItem->QueryInterface(&spMailItem);//Get The selected item
if(spMailItem)
{
spMailItem->put_Categories(L"Undelivered");
spMailItem->Save();
}
}
}
}
}
前もって感謝します。