OL2000 'Illegal instruction' after adding menu to ActiveMenubar

G

Georg-Hendrik

This one really puzzles me.

I'm developing an Outlook COM Add-in, C++/ATL, which is to work under
Outlook 2k - 2k7. I've simplified the code and isolated the problem in a
default VS2005 Extensibility project, of which below you can find the code
from the OnConnection method.

The project compiles fine and shows no issues under Outlook 2007.
Also in Outlook 2000, everything works fine until Close is pressed.
Then it faults with 'exception at 0x030f0db6 in OUTLOOK.EXE: 0xC000001D:
Illegal Instruction.'

It only faults if I press buttons on the toolbar (e.g. Calendar, Contacts)
before exiting.

The problem seems to involve use of the ActiveMenubar - if I add a new
CommandBar and add the ControlPopup to that, the problem does not occur.

Who can help?

Sincere regards,

Georg-Hendrik


Attachement 1: OnConnection Method (in standard VS2005 Extensibility project)

STDMETHODIMP CConnect::OnConnection(...)
{
// Default code
pApplication->QueryInterface(__uuidof(IDispatch), (LPVOID*)&m_pApplication);
pAddInInst->QueryInterface(__uuidof(IDispatch), (LPVOID*)&m_pAddInInstance);

// Isolated problem code starts here
::MessageBox(NULL, _T("Connection"), NULL, 0);

CComQIPtr<Outlook::_Application> soOutlook;
CComPtr<Outlook::_Explorer> soExplorer;
CComPtr<Office::_CommandBars> soBars;
CComPtr<Office::CommandBar> soActiveMenu;
CComPtr<Office::CommandBarControls> soMenuItems;
CComPtr<Office::CommandBarControl> soMyMenuItem;

try
{
// Get to the active Outlook menu bar controls...
soOutlook = pApplication;
soExplorer = soOutlook->ActiveExplorer();
soBars = soExplorer->GetCommandBars();
soActiveMenu = soBars->ActiveMenuBar;
soMenuItems = soActiveMenu->GetControls();

// ... and add an empty pop-up menu.
soMyMenuItem = soMenuItems->Add(msoControlPopup, vtMissing, vtMissing,
vtMissing, VARIANT_TRUE);

soMyMenuItem->Caption = _T("MyMenuItem");
soMyMenuItem->Tag = _T("my.menuitem");
}

catch (...)
{
::MessageBox(NULL, _T("BFE"), NULL, 0);
}

// The error shows regardless of the following
// few lines of code; Setting the CComPtr s to
// NULL did work for five minutes (literally...)

soMyMenuItem = NULL;
soMenuItems = NULL;
soActiveMenu = NULL;
soBars = NULL;
soExplorer = NULL;

return S_OK;
}
 
D

Dmitry Streblechenko

How do you subscribe to teh Click events? Or does the problem occur even if
you do not subscribe to the events at all?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

Georg-Hendrik

Thanks for the quick response.

The problem occurs even without subscribing to events. The original code
subscribed to Click events. Above attached code does not. In both cases, the
illegal instruction occurs at close of Outlook.

If it helps in narrowing the problem, calling soMyMenuItem->Delete()
immediatly after setting Caption and Tag, produces an access violation.
 
D

Dmitry Streblechenko

Hmmm.. I don't know. Out of curiosity, why are you using
CommandBars.ActiveMenuBar? Have you tried to explicitly specify which
toolbar you want (CommandBars.Item["Toolbar Name"])?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

Georg-Hendrik

Thanks for the suggestion. I use CommandBars.ActiveMenuBar to be sure that I
am getting the commandbar that also holds the File, Edit, etc. menus.
As you suggested, I could also refer to commandbars.Item["Menu Bar"], but I
am not sure wheter, in all localised versions of Outlook, the name is also
"Menu Bar" . ActiveMenuBar always exists, and refers to the right bar.
I did try it, but the illegal instruction remains.
Is there perhaps something odd in my ComPtr's? Do you know of any working
ATL/C++ examples?

Sincerely,

Georg-Hendrik




Dmitry Streblechenko said:
Hmmm.. I don't know. Out of curiosity, why are you using
CommandBars.ActiveMenuBar? Have you tried to explicitly specify which
toolbar you want (CommandBars.Item["Toolbar Name"])?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Georg-Hendrik said:
This one really puzzles me.

I'm developing an Outlook COM Add-in, C++/ATL, which is to work under
Outlook 2k - 2k7. I've simplified the code and isolated the problem in a
default VS2005 Extensibility project, of which below you can find the code
from the OnConnection method.

The project compiles fine and shows no issues under Outlook 2007.
Also in Outlook 2000, everything works fine until Close is pressed.
Then it faults with 'exception at 0x030f0db6 in OUTLOOK.EXE: 0xC000001D:
Illegal Instruction.'

It only faults if I press buttons on the toolbar (e.g. Calendar, Contacts)
before exiting.

The problem seems to involve use of the ActiveMenubar - if I add a new
CommandBar and add the ControlPopup to that, the problem does not occur.

Who can help?

Sincere regards,

Georg-Hendrik


Attachement 1: OnConnection Method (in standard VS2005 Extensibility
project)

STDMETHODIMP CConnect::OnConnection(...)
{
// Default code
pApplication->QueryInterface(__uuidof(IDispatch),
(LPVOID*)&m_pApplication);
pAddInInst->QueryInterface(__uuidof(IDispatch),
(LPVOID*)&m_pAddInInstance);

// Isolated problem code starts here
::MessageBox(NULL, _T("Connection"), NULL, 0);

CComQIPtr<Outlook::_Application> soOutlook;
CComPtr<Outlook::_Explorer> soExplorer;
CComPtr<Office::_CommandBars> soBars;
CComPtr<Office::CommandBar> soActiveMenu;
CComPtr<Office::CommandBarControls> soMenuItems;
CComPtr<Office::CommandBarControl> soMyMenuItem;

try
{
// Get to the active Outlook menu bar controls...
soOutlook = pApplication;
soExplorer = soOutlook->ActiveExplorer();
soBars = soExplorer->GetCommandBars();
soActiveMenu = soBars->ActiveMenuBar;
soMenuItems = soActiveMenu->GetControls();

// ... and add an empty pop-up menu.
soMyMenuItem = soMenuItems->Add(msoControlPopup, vtMissing, vtMissing,
vtMissing, VARIANT_TRUE);

soMyMenuItem->Caption = _T("MyMenuItem");
soMyMenuItem->Tag = _T("my.menuitem");
}

catch (...)
{
::MessageBox(NULL, _T("BFE"), NULL, 0);
}

// The error shows regardless of the following
// few lines of code; Setting the CComPtr s to
// NULL did work for five minutes (literally...)

soMyMenuItem = NULL;
soMenuItems = NULL;
soActiveMenu = NULL;
soBars = NULL;
soExplorer = NULL;

return S_OK;
}
 
D

Dmitry Streblechenko

You migth want to look at the C++ samples at
http://www.outlookcode.com/article.aspx?ID=36

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Dmitry Streblechenko said:
Hmmm.. I don't know. Out of curiosity, why are you using
CommandBars.ActiveMenuBar? Have you tried to explicitly specify which
toolbar you want (CommandBars.Item["Toolbar Name"])?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Georg-Hendrik said:
This one really puzzles me.

I'm developing an Outlook COM Add-in, C++/ATL, which is to work under
Outlook 2k - 2k7. I've simplified the code and isolated the problem in a
default VS2005 Extensibility project, of which below you can find the
code
from the OnConnection method.

The project compiles fine and shows no issues under Outlook 2007.
Also in Outlook 2000, everything works fine until Close is pressed.
Then it faults with 'exception at 0x030f0db6 in OUTLOOK.EXE: 0xC000001D:
Illegal Instruction.'

It only faults if I press buttons on the toolbar (e.g. Calendar,
Contacts)
before exiting.

The problem seems to involve use of the ActiveMenubar - if I add a new
CommandBar and add the ControlPopup to that, the problem does not occur.

Who can help?

Sincere regards,

Georg-Hendrik


Attachement 1: OnConnection Method (in standard VS2005 Extensibility
project)

STDMETHODIMP CConnect::OnConnection(...)
{
// Default code
pApplication->QueryInterface(__uuidof(IDispatch),
(LPVOID*)&m_pApplication);
pAddInInst->QueryInterface(__uuidof(IDispatch),
(LPVOID*)&m_pAddInInstance);

// Isolated problem code starts here
::MessageBox(NULL, _T("Connection"), NULL, 0);

CComQIPtr<Outlook::_Application> soOutlook;
CComPtr<Outlook::_Explorer> soExplorer;
CComPtr<Office::_CommandBars> soBars;
CComPtr<Office::CommandBar> soActiveMenu;
CComPtr<Office::CommandBarControls> soMenuItems;
CComPtr<Office::CommandBarControl> soMyMenuItem;

try
{
// Get to the active Outlook menu bar controls...
soOutlook = pApplication;
soExplorer = soOutlook->ActiveExplorer();
soBars = soExplorer->GetCommandBars();
soActiveMenu = soBars->ActiveMenuBar;
soMenuItems = soActiveMenu->GetControls();

// ... and add an empty pop-up menu.
soMyMenuItem = soMenuItems->Add(msoControlPopup, vtMissing, vtMissing,
vtMissing, VARIANT_TRUE);

soMyMenuItem->Caption = _T("MyMenuItem");
soMyMenuItem->Tag = _T("my.menuitem");
}

catch (...)
{
::MessageBox(NULL, _T("BFE"), NULL, 0);
}

// The error shows regardless of the following
// few lines of code; Setting the CComPtr s to
// NULL did work for five minutes (literally...)

soMyMenuItem = NULL;
soMenuItems = NULL;
soActiveMenu = NULL;
soBars = NULL;
soExplorer = NULL;

return S_OK;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top