J
Jim
Hi,
I'm developing an addin for Outlook 2003 in C++. The addin dll will
add a new menu button on outlook item menu, this works if Word is not
involved. If I check "use Office word 2003 to edit email message" in
the tool->options->mail format, the menu can not be added.
I try to trace the issue and I found that Commandbars can not be got
through inspector. I'm trying to solve the problem with some code that
attempt to add the menu to Word's commandbar, but it failed at this
line in AttachMenu function:
hr = editWordDoc->get_CommandBars(&spCmdBars);
Any ideas on why this doesn't work? Is this the right way to add menu
to OL2003's new mail/view message window when Word is used?
The following codes are relevant codes:
//Invoke function can get the inspector of application
STDMETHODIMP CSecurityAddin::Invoke(DISPID dispidMember,REFIID
riid,LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams, VARIANT*
pvarResult,
EXCEPINFO* pExcepInfo, UINT*
puArgErr)
{
HRESULT hr = S_OK;
if(dispidMember == 0xf001)
{
if(pDispParams == NULL)
{
return E_FAIL;
}
if(pDispParams->cArgs > 0)
{
//the only parameter is an Inspector*
IDispatchPtr pDisp(pDispParams->rgvarg[0].pdispVal);
CComQIPtr<_Inspector> spInspector(pDisp);
Outlook::OlObjectClass CurObjectCls;
spInspector->get_Class(&CurObjectCls);
CComQIPtr<IDispatch> spInspectorItem;
spInspector->get_CurrentItem(&spInspectorItem);
CComQIPtr<Outlook::_MailItem> spMailItem(spInspectorItem);
if(spMailItem == NULL)
{
return E_FAIL;
}
OlObjectClass type;
spMailItem->get_Class(&type);
if(type == olMail)
{
CMenu* pMenu = new CMenu();
if(!pMenu)
{
return E_OUTOFMEMORY;
}
pMenu->Init(m_spApp, spInspector);
m_vecPMenu.push_back(pMenu);
}
}
}
else
{
return E_FAIL;
}
return hr;
}
//Init menu
HRESULT CMenu::Init(CComQIPtr <Outlook::_Application> spApp,
CComQIPtr<Outlook::_Inspector> spInspector)
{
ATLASSERT(spApp);
ATLASSERT(spInspector);
LogFile("Start Init!");
m_spApp = spApp;
m_spInspector = spInspector;
if(FAILED(AttachMenu(m_spInspector)))
{
return E_FAIL;
}
LogFile("End Init!");
return S_OK;
}
//
HRESULT CMenu::AttachMenu(CComQIPtr<_Inspector> spInspector)
{
LogFile("Start AttachMenu!");
HRESULT hr = S_OK;
ATLASSERT(spInspector);
m_spInspector = spInspector;
CComPtr<Office::_CommandBars> spCmdBars;
hr = spInspector->get_CommandBars(&spCmdBars); //actually if the
option is checked, the function get the error code
OlEditorType editType;
spInspector->get_EditorType(&editType);
if(editType == olEditorWord)
{
LogFile("Using the word to edit email message!");
CComPtr<MSWord::_Document> editWordDoc;
hr = spInspector->get_WordEditor((IDispatch* *)&editWordDoc);
if(FAILED(hr))
{
LogFile("spInspector->get_WordEditor Failed!");
return hr;
}
ATLASSERT(editWordDoc);
CComPtr<MSWord::_Application> editWordApp;
hr = editWordDoc->get_Application(&editWordApp);
if(FAILED(hr))
{
LogFile("editWordDoc->get_Application Failed!");
return hr;
}
else
{
LogFile("Get_Application success");
}
ATLASSERT(editWordApp);
hr = editWordDoc->get_CommandBars(&spCmdBars);
if(FAILED(hr))
{
LogFile("editWordApp->get_CommandBars Failed!");
return hr;
}
MessageBox(NULL,"NULL","TRACE",NULL);
}
if(FAILED(hr))
{
LogFile("spInspector->get_CommandBars failed!");
return hr;
}
ATLASSERT(spCmdBars);
CComQIPtr<CommandBar> spTopMenu;
spTopMenu = spCmdBars->GetActiveMenuBar();
ATLASSERT(spTopMenu);
//... add item into the menu item and add item into the menu.
.............................
}
I'm developing an addin for Outlook 2003 in C++. The addin dll will
add a new menu button on outlook item menu, this works if Word is not
involved. If I check "use Office word 2003 to edit email message" in
the tool->options->mail format, the menu can not be added.
I try to trace the issue and I found that Commandbars can not be got
through inspector. I'm trying to solve the problem with some code that
attempt to add the menu to Word's commandbar, but it failed at this
line in AttachMenu function:
hr = editWordDoc->get_CommandBars(&spCmdBars);
Any ideas on why this doesn't work? Is this the right way to add menu
to OL2003's new mail/view message window when Word is used?
The following codes are relevant codes:
//Invoke function can get the inspector of application
STDMETHODIMP CSecurityAddin::Invoke(DISPID dispidMember,REFIID
riid,LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams, VARIANT*
pvarResult,
EXCEPINFO* pExcepInfo, UINT*
puArgErr)
{
HRESULT hr = S_OK;
if(dispidMember == 0xf001)
{
if(pDispParams == NULL)
{
return E_FAIL;
}
if(pDispParams->cArgs > 0)
{
//the only parameter is an Inspector*
IDispatchPtr pDisp(pDispParams->rgvarg[0].pdispVal);
CComQIPtr<_Inspector> spInspector(pDisp);
Outlook::OlObjectClass CurObjectCls;
spInspector->get_Class(&CurObjectCls);
CComQIPtr<IDispatch> spInspectorItem;
spInspector->get_CurrentItem(&spInspectorItem);
CComQIPtr<Outlook::_MailItem> spMailItem(spInspectorItem);
if(spMailItem == NULL)
{
return E_FAIL;
}
OlObjectClass type;
spMailItem->get_Class(&type);
if(type == olMail)
{
CMenu* pMenu = new CMenu();
if(!pMenu)
{
return E_OUTOFMEMORY;
}
pMenu->Init(m_spApp, spInspector);
m_vecPMenu.push_back(pMenu);
}
}
}
else
{
return E_FAIL;
}
return hr;
}
//Init menu
HRESULT CMenu::Init(CComQIPtr <Outlook::_Application> spApp,
CComQIPtr<Outlook::_Inspector> spInspector)
{
ATLASSERT(spApp);
ATLASSERT(spInspector);
LogFile("Start Init!");
m_spApp = spApp;
m_spInspector = spInspector;
if(FAILED(AttachMenu(m_spInspector)))
{
return E_FAIL;
}
LogFile("End Init!");
return S_OK;
}
//
HRESULT CMenu::AttachMenu(CComQIPtr<_Inspector> spInspector)
{
LogFile("Start AttachMenu!");
HRESULT hr = S_OK;
ATLASSERT(spInspector);
m_spInspector = spInspector;
CComPtr<Office::_CommandBars> spCmdBars;
hr = spInspector->get_CommandBars(&spCmdBars); //actually if the
option is checked, the function get the error code
OlEditorType editType;
spInspector->get_EditorType(&editType);
if(editType == olEditorWord)
{
LogFile("Using the word to edit email message!");
CComPtr<MSWord::_Document> editWordDoc;
hr = spInspector->get_WordEditor((IDispatch* *)&editWordDoc);
if(FAILED(hr))
{
LogFile("spInspector->get_WordEditor Failed!");
return hr;
}
ATLASSERT(editWordDoc);
CComPtr<MSWord::_Application> editWordApp;
hr = editWordDoc->get_Application(&editWordApp);
if(FAILED(hr))
{
LogFile("editWordDoc->get_Application Failed!");
return hr;
}
else
{
LogFile("Get_Application success");
}
ATLASSERT(editWordApp);
hr = editWordDoc->get_CommandBars(&spCmdBars);
if(FAILED(hr))
{
LogFile("editWordApp->get_CommandBars Failed!");
return hr;
}
MessageBox(NULL,"NULL","TRACE",NULL);
}
if(FAILED(hr))
{
LogFile("spInspector->get_CommandBars failed!");
return hr;
}
ATLASSERT(spCmdBars);
CComQIPtr<CommandBar> spTopMenu;
spTopMenu = spCmdBars->GetActiveMenuBar();
ATLASSERT(spTopMenu);
//... add item into the menu item and add item into the menu.
.............................
}