Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Com VSTO 2007 outlook加载项崩溃_Com_Outlook Addin_Outlook 2007 - Fatal编程技术网

Com VSTO 2007 outlook加载项崩溃

Com VSTO 2007 outlook加载项崩溃,com,outlook-addin,outlook-2007,Com,Outlook Addin,Outlook 2007,我正在使用COM创建VSTO 2007 outlook加载项。它从outlook读取所有邮件项,并将未送达的邮件项标记为未送达 我使用下面的代码将未送达的邮件标记为未送达。用可读颜色标记的代码有时会崩溃。请告诉我这个问题 HRESULT hrGetSelectedItem LPDISPATCH spOlSelectedItem = NULL; CComPtr<Outlook::_Explorer> s

我正在使用COM创建VSTO 2007 outlook加载项。它从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();

                                                                             }

                                                             }

                                            }

                            }

            }
LPDISPATCH spOlSelectedItem=NULL;
首席专家;
//查找所选项目
斯波尔塞尔伯爵;
如果(m_spApp)
{
//在桌面顶部获取当前活动的资源管理器
hrGetSelectedItem=m_spApp->ActiveExplorer(&spExplorer);
如果(成功(hrGetSelectedItem))
{
hrGetSelectedItem=spExplorer->get_Selection(&spOlSel);
如果(失败(hrGetSelectedItem))
{   
MessageBox(NULL,GetStringFromTable(IDS_SELECTITEM),MSGBOX_标题,MB_OK | MB_图标信息);
返回;
}
iMailIndex+=1;
变异指数;
covIndex.vt=vt_I4;
covIndex.lVal=iMailIndex;
if(spOlSel)
{
hrGetSelectedItem=spOlSel->Item(covIndex,&spOlSelectedItem);
CComQIPtr spMailItem;
if(spOlSelectedItem)
{
hrGetSelectedItem=spOlSelectedItem->QueryInterface(&spMailItem);//获取所选项目
如果(spMailItem)
{
spMailItem->put_类别(L“未送达”);
spMailItem->Save();
}
}
}
}
}LPDISPATCH spOlSelectedItem=NULL;
首席专家;
//查找所选项目
斯波尔塞尔伯爵;
如果(m_spApp)
{
//在桌面顶部获取当前活动的资源管理器
hrGetSelectedItem=m_spApp->ActiveExplorer(&spExplorer);
如果(成功(hrGetSelectedItem))
{
hrGetSelectedItem=spExplorer->get_Selection(&spOlSel);
如果(失败(hrGetSelectedItem))
{   
MessageBox(NULL,GetStringFromTable(IDS_SELECTITEM),MSGBOX_标题,MB_OK | MB_图标信息);
返回;
}
iMailIndex+=1;
变异指数;
covIndex.vt=vt_I4;
covIndex.lVal=iMailIndex;
if(spOlSel)
{
hrGetSelectedItem=spOlSel->Item(covIndex,&spOlSelectedItem);
CComQIPtr spMailItem;
if(spOlSelectedItem)
{
hrGetSelectedItem=spOlSelectedItem->QueryInterface(&spMailItem);//获取所选项目
如果(spMailItem)
{
spMailItem->put_类别(L“未送达”);
spMailItem->Save();
}
}
}
}
}

提前感谢。

您需要检查spExplorer是否为空。Outlook可以在没有浏览器的情况下打开。

用颜色标记的代码是什么?如果需要帮助,请尝试格式化。另外,为什么要将智能指针与标准指针混合使用?您应该将LPDISPATCH更改为CComPtr,否则将丢失发布调用。即使spExplorer不为null,hrGetSelectedItem=spExplorer->get_Selection(&spOlSel);正在崩溃。当我选择文件夹中的所有邮件项目时,只有此函数调用崩溃。您可以访问OutlookSpy中的选择吗?单击Outlook Spy工具栏上的资源管理器按钮,