Errors while adding new item to main menu

R

Ramazan

I want to add new entry to main menu like "Help".
this code is adding to new entry to main menu bar behind of help
entry. But adding twice. Adding extra one entry to 0(zero) point in
main menu.
Thats first problem for me.
Another problem is this;
while outlook closing it gives that error "Unhandled exception at
0x03b3bab2 in OUTLOOK.EXE: 0xC000001D: Illegal Instruction."
when i remove my code it is working correctly.
How can i correct this error ?

in MAPI:
install(LPEXCHEXTCALLBACK peecb, ULONG eecontext, ULONG ulFlags)

function i write this code for adding new item to main menu as new
menu:

using namespace Outlook;
using namespace Office;

Outlook::_ApplicationPtr mOutlookApp = getOutlookApp(peecb);
Outlook::_ExplorerPtr lpExp=mOutlookApp->ActiveExplorer();
CComPtr<Office::_CommandBars> spCmdBars;
HRESULT hr = lpExp->get_CommandBars(&spCmdBars);
if (FAILED(hr))
{
//return NULL;
}
Office::CommandBarPtr lAnaMenu = spCmdBars->GetActiveMenuBar();
CommandBarControlsPtr lAnaMenuKontrols = lAnaMenu->GetControls();
CommandBarControlPtr lEsyaMenuPtr=NULL;
lMenuCount = lAnaMenuKontrols->GetCount();
CComVariant vtEmpty (DISP_E_PARAMNOTFOUND, VT_ERROR);
CComVariant vtFalse (VARIANT_FALSE);
CComVariant popupType (msoControlPopup);
CComVariant buttonType (msoControlButton);
lEsyaMenuPtr = lAnaMenuKontrols->Add(popupType,
vtEmpty,vtEmpty,lMenuCount, VARIANT_TRUE);

if (lEsyaMenuPtr==NULL)
{
return false;
}
lEsyaMenuPtr->PutCaption("TestAddinInMainMenu");


////////////////////////
I get ApplicationPtr in this function
I get callback function in MAPI install(LPEXCHEXTCALLBACK peecb, ULONG
eecontext, ULONG ulFlags) function with case EECONTEXT_VIEWER

//Getting _ApplicationPtr from callback
Outlook::_ApplicationPtr getOutlookApp(LPEXCHEXTCALLBACK iPeecb)
{
Outlook::_ApplicationPtr lRetAppPtr;
try
{
IOutlookExtCallback *pOutlook = NULL;
HRESULT hRes = iPeecb->QueryInterface(IID_IOutlookExtCallback,
(void **) &pOutlook);
if (pOutlook)
{
IUnknown *pUnk = NULL;
pOutlook->GetObject(&pUnk);
LPDISPATCH lpMyDispatch;
if (pUnk != NULL)
{
hRes = pUnk->QueryInterface(IID_IDispatch,
(void **) &lpMyDispatch);
pUnk->Release();
}
if (lpMyDispatch)
{
OLECHAR * szApplication = L"Application";
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
DISPID dspid;
VARIANT vtResult;
lpMyDispatch->GetIDsOfNames(IID_NULL, &szApplication, 1,
LOCALE_SYSTEM_DEFAULT, &dspid);
lpMyDispatch->Invoke(dspid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD,
&dispparamsNoArgs, &vtResult, NULL, NULL);
lpMyDispatch->Release();

lRetAppPtr= vtResult.pdispVal;
return lRetAppPtr;
}
}
}
catch(...)
{
}
return lRetAppPtr;
}

////////////////////////
 
R

Ramazan

I want to add new entry to main menu like  "Help".
this code is adding to new entry to main menu bar behind of help
entry. But adding twice. Adding extra one entry to 0(zero) point in
main menu.
Thats first problem for me.
Another problem is this;
while outlook closing it gives that error "Unhandled exception at
0x03b3bab2 in OUTLOOK.EXE: 0xC000001D: Illegal Instruction."
when i remove my code it is working correctly.
How can i correct this error ?

in MAPI:
install(LPEXCHEXTCALLBACK peecb, ULONG eecontext, ULONG ulFlags)

function i write this code for adding new item to main menu as new
menu:

using namespace Outlook;
using namespace Office;

        Outlook::_ApplicationPtr mOutlookApp = getOutlookApp(peecb);
        Outlook::_ExplorerPtr lpExp=mOutlookApp->ActiveExplorer();
        CComPtr<Office::_CommandBars> spCmdBars;
        HRESULT hr = lpExp->get_CommandBars(&spCmdBars);
        if (FAILED(hr))
        {
                //return NULL;
        }
        Office::CommandBarPtr lAnaMenu = spCmdBars->GetActiveMenuBar();
        CommandBarControlsPtr lAnaMenuKontrols = lAnaMenu->GetControls();
CommandBarControlPtr lEsyaMenuPtr=NULL;
        lMenuCount = lAnaMenuKontrols->GetCount();
CComVariant vtEmpty    (DISP_E_PARAMNOTFOUND, VT_ERROR);
        CComVariant vtFalse    (VARIANT_FALSE);
        CComVariant popupType  (msoControlPopup);
        CComVariant buttonType (msoControlButton);
        lEsyaMenuPtr = lAnaMenuKontrols->Add(popupType,
vtEmpty,vtEmpty,lMenuCount, VARIANT_TRUE);

        if (lEsyaMenuPtr==NULL)
        {
                return false;
        }
        lEsyaMenuPtr->PutCaption("TestAddinInMainMenu");

////////////////////////
I get ApplicationPtr in this function
I get callback function in MAPI install(LPEXCHEXTCALLBACK peecb, ULONG
eecontext, ULONG ulFlags) function with case EECONTEXT_VIEWER

//Getting _ApplicationPtr from callback
Outlook::_ApplicationPtr getOutlookApp(LPEXCHEXTCALLBACK iPeecb)
{
        Outlook::_ApplicationPtr lRetAppPtr;
        try
        {
                IOutlookExtCallback *pOutlook = NULL;
                HRESULT hRes = iPeecb->QueryInterface(IID_IOutlookExtCallback,
                        (void **) &pOutlook);
                if (pOutlook)
                {
                        IUnknown *pUnk = NULL;
                        pOutlook->GetObject(&pUnk);
                        LPDISPATCH lpMyDispatch;
                        if (pUnk != NULL)
                        {
                                hRes = pUnk->QueryInterface(IID_IDispatch,
                                        (void **) &lpMyDispatch);
                                pUnk->Release();
                        }
                        if (lpMyDispatch)
                        {
                                OLECHAR *szApplication = L"Application";
                                DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
                                DISPID dspid;
                                VARIANT vtResult;
                                lpMyDispatch->GetIDsOfNames(IID_NULL, &szApplication, 1,
                                        LOCALE_SYSTEM_DEFAULT, &dspid);
                                lpMyDispatch->Invoke(dspid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
                                        DISPATCH_METHOD,
                                        &dispparamsNoArgs, &vtResult, NULL, NULL);
                                lpMyDispatch->Release();

                                lRetAppPtr= vtResult.pdispVal;
                                return lRetAppPtr;
                        }
                }
        }
        catch(...)
        {
        }
        return lRetAppPtr;

}

////////////////////////

I must also give that information. This code is working correcly in
outlook 2003 but gives errors which i mentioned above in outlook 2000.
Ramazan
 
S

SvenC

Hi Ramazan,
Office::CommandBarPtr lAnaMenu = spCmdBars->GetActiveMenuBar();

Check your smart pointers before you use them!

if(IAnaMenu == NULL)
--> some error handling

Newer Outlook versions have more classes/methods/properties, so you
have to check if Outlook supports what you try to use.
 
R

Ramazan

Hi Ramazan,


Check your smart pointers before you use them!

if(IAnaMenu == NULL)
 --> some error handling

Newer Outlook versions have more classes/methods/properties, so you
have to check if Outlook supports what you try to use.

The proplem is not related to checking pointer. In outlook 2000 at new
mail screen mail menu, i can add new entry to main menu and it is no
problem while closing outlook.

I have removed that code from Extended MAPI from install
(LPEXCHEXTCALLBACK peecb, ULONG eecontext, ULONG ulFlags) method and
insert to onRead() method for test.
in onRead() method it is worked correctly and no error.

It may be related to mapi install() function. May be install function
with EECONTEXT_VIEWER must be return and than menu must be
inserted .But i don't know really.

Do you know in which method i can put menu insertion code which i
write.
Thanks .
Ramazan
 
S

SvenC

Hi Ramazan,
The proplem is not related to checking pointer. In outlook 2000 at new
mail screen mail menu, i can add new entry to main menu and it is no
problem while closing outlook.

Can you build a debug dll of your addin and start a debug session with
Outlook.exe as the debuggee? Then you can see where the crash occurs.

Do you store any COM objects, so that they live longer than the
callback methods called in your client extension?
If yes, try not to store those pointers and see if that helps.
 
Top