View Single Post
  #1  
Old December 20th 07, 02:21 PM posted to microsoft.public.outlook.program_addins
Jim[_6_]
external usenet poster
 
Posts: 5
Default New menu on OL2003 doesn't work when Word is used to edit msg

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);

CComQIPtrIDispatch spInspectorItem;
spInspector-get_CurrentItem(&spInspectorItem);
CComQIPtrOutlook::_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,
CComQIPtrOutlook::_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;
CComPtrOffice::_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!");
CComPtrMSWord::_Document editWordDoc;
hr = spInspector-get_WordEditor((IDispatch* *)&editWordDoc);

if(FAILED(hr))
{
LogFile("spInspector-get_WordEditor Failed!");
return hr;
}
ATLASSERT(editWordDoc);
CComPtrMSWord::_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);
CComQIPtrCommandBar spTopMenu;
spTopMenu = spCmdBars-GetActiveMenuBar();
ATLASSERT(spTopMenu);

//... add item into the menu item and add item into the menu.
.............................
}

Ads