Hi all,
I am facing one weired problem. I am adding one menu item to the right click context menu for my add-in. I pasted my function below. This function is working fine with Outlook 2002 and Outlook 2003. But it is crashing on Outlook 2000 for one specific scenario. After initializing Outlook if I right click on normal mail item and then if I right click on meeting item Outlook just crashes with the Access violation error. Only difference between these two menus are for meeting item there are more no of options in the context menu. If user does it vice versa then it works fine. ( first right click on meeting item and then mail item.) I am not able to understand this behaviour of Outlook 2000. If anyone knows about this issue, please let me know about the same.
I have noted down the crash line as "*******Crash occurring here. *******" in the code.
void __stdcall CIPPlugin::OnContextMenuUpdate() { CComPtr<Office::CommandBar> pCmdBar; CComPtr<Office::CommandBarControls> pMenuControls; Office::MsoBarProtection oldProtectionLevel; BOOL bFound =false; int Count =0;
/// //m_spCommandbars is member variable of CIPPlugin class. //We are getting it in OnStartupComplete // result= pActiveExplorer->get_CommandBars(&pExplorerCommandBars); ///
if( m_spCommandbars ) m_spCommandbars->get_Count(&Count);
for(long i = 0; i < Count; i++) { CComPtr<Office::CommandBar> pTempBar; CComVariant vItem(i+1); m_spCommandbars->get_Item(vItem,&pTempBar); if(pTempBar) { BSTR bstrName; pTempBar->get_Name(&bstrName);
if(!wcscmp(L"Context Menu", bstrName)) { pCmdBar = pTempBar; bFound = true; pCmdBar->Reset(); //*******Crash occurring here. ******* break; }
::SysFreeString(bstrName);
} } if(!bFound) return;
if(pCmdBar) { pCmdBar->get_Controls(&pMenuControls); pCmdBar->get_Protection(&oldProtectionLevel); pCmdBar->put_Protection(Office::msoBarNoProtection); CComVariant vtType(Office::msoControlButton);
CComPtr<Office::CommandBarControl> pContextMenuControl; pSPAMContextMenuControl=pMenuControls->Add(CComVariant( Office::msoControlButton), CComVariant(1), CComVariant(1), CComVariant(1), CComVariant(VARIANT_TRUE) ); if(pContextMenuControl==NULL) { LOG_ERR_MESSAGE(_T("pMenuControls->Add") , GetLastError()); pCmdBar.Release(); return; } pContextMenuControl->QueryInterface(&m_pContextMenu);
bstrTemp.LoadString(IDS_BUTTON_CAPTION); if( m_pContextMenu ) { m_pContextMenu->put_Tag(bstrTemp); m_pContextMenu->put_Caption(bstrTemp); m_pContextMenu->put_Priority(1) ; m_pContextMenu->put_Visible(TRUE); m_pContextMenu->put_Style(Office::msoButtonIconAndCaption);
hr = ContextMenuEvents::DispEventAdvise((IDispatch*)m_pSPAMContextMenu); }
pCmdBar->put_Protection(oldProtectionLevel); pCmdBar.Release(); } }
|
|