首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VSTO 2007 outlook加载项崩溃

VSTO 2007 outlook加载项崩溃
EN

Stack Overflow用户
提问于 2013-05-18 16:47:49
回答 1查看 177关注 0票数 0

我正在使用COM创建VSTO 2007 outlook外接程序。它从outlook中读取所有邮件,并将未投递的邮件标记(分类)为未投递。

我使用下面的代码将未送达的邮件项目标记为未送达。在read colour中标记的代码有时会崩溃。请给我提个建议。

HRESULT hrGetSelectedItem;

代码语言:javascript
复制
            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();

                                                                             }

                                                             }

                                            }

                            }

            }

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-05-19 04:16:47

您需要检查spExplorer是否不为空。Outlook可以在没有资源管理器的情况下打开。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16622329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档