View Full Version : GetMenu() issue with VS2010

10-29-2010, 05:03 AM

I'm migrating an application from Visual C-6.0 to Visual Studio 2010.
I also upgraded to Stingray Toolkit 10.4

From VC-6.0 to VS-2005: OK (many fixes but compiles and runs ok).
From VS-2005 to VS-2010: NOK: compiles but breaks at execution with an assertion violation:

_AFXWIN_INLINE int CMenu::GetMenuItemCount() const
{ ASSERT(::IsMenu(m_hMenu)); return ::GetMenuItemCount(m_hMenu); }

The m_hMenu is NULL because GetMenu() now always returns NULL
whereas it returned the right value with VS-2005.

In the InitInstance() function, I added for debug purpose many calls to GetMenu().
They all return NULL with VS-2010:
if (!m_pMainFrame || !m_pMainFrame->LoadFrame(IDR_MAINFRAME)) {
delete m_pMainFrame;
TRACE0 ("\nFailed to create mainframe");
return FALSE;
m_pMainWnd = m_pMainFrame;
m_pMainFrame->GetMenu(); /* VS2005, result == OK, is SECMDIFrameWnd::GetMenu() */
((CWnd*)m_pMainFrame)->GetMenu(); /* VS2005, result == NULL */
((CMainFrame*)m_pMainFrame)->GetMenu(); /* VS2005, result == OK */
((CMDIFrameWnd*)m_pMainFrame)->GetMenu(); /* VS2005, result == NULL */
CMenu *pMenu = AfxGetMainWnd()->CWnd::GetMenu(); /* VS2005, result == NULL */
((CFrameWnd*)m_pMainFrame)->GetMenu(); /* VS2005, result == NULL */
((SECMDIFrameWnd*)m_pMainFrame)->GetMenu(); /* VS2005, result == OK */
((SECFrameWnd*)m_pMainFrame)->GetMenu(); /* VS2005, Assertion violation */
/* computing pThis->GetMenuBar()->GetCurMenuID() as pThis->GetMenuBar() == NULL */

I tried the demo application:
Stingray Studio 10.4\Samples\Toolkit\MFC\Docking\MenuBar\MdiAdv\md iadv10.sln

adding in "Mdiadv.cpp" the same GetMenu() calls than above. It always returns NULL with VS-2010.

Does someone have any idea to fix this issue ?

10-29-2010, 05:05 AM
I added "m_pMenuBar->SwitchMenu(IDR_MAINFRAME);" at the end of CMainFrame::OnCreate()
without success. This was following:
KBase => SECFrameWnd::GetMenu() returns NULL

10-29-2010, 05:07 AM
I replaced in Stingray Studio 10.4\Src\Toolkit\mdi\swinmdi.cpp

if(AfxGetMainWnd()->GetMenu() == NULL)


CMenu *pMenu = AfxGetMainWnd()->CWnd::GetMenu();
if(pMenu == NULL)

and recompiled the Toolkit libraries without success. This was following:
MdiAdv sample VS2008 bug http://www.roguewave.com/forum/showthread.php?t=168

10-29-2010, 05:36 AM
While tracing the execution of my program, I come into:

SECMDIFrameWnd::LoadFrame() {
// save the default menu handle
ASSERT(m_hWnd != NULL);
m_hMenuDefault = ::GetMenu(m_hWnd); ==> and I get NULL

11-02-2010, 10:32 AM
If I replace:

if (!m_pMainFrame || !m_pMainFrame->LoadFrame(IDR_MAINFRAME)) {

that calls SECMDIFrameWnd::LoadFrame() by:

if (!m_pMainFrame || !m_pMainFrame->CMDIFrameWnd::LoadFrame(IDR_MAINFRAME)) {

then there is no ASSERT break and I get TWO main menus: a fixed one and a "floating" one (one that can be detached and moved).

The CMDIFrameWnd::LoadFrame() may do some initialization needed by SECMDIFrameWnd::LoadFrame()...

Nobody got this issue ?

11-03-2010, 05:31 AM
I'm investigating in the direction given by current Microsoft forum thread:


11-04-2010, 07:23 AM
the issue is FIXED !

Terry Crook from Stingray support told me the modifications I had to apply.

- first: replace in Stingray Studio 10.4\Src\Toolkit\mdi\swinmdi.cpp the GetMenu() call like explained in http://www.roguewave.com/forum/showthread.php?t=168

- second, in swinmdi.cpp too, revert the change made in SS10.4: remove the code in SECMDIFrameWnd::GetMenu() starting with '#if _MSC_VER >= 1500' and ending with '#else', and also the corresponding '#endif'.

-third: rebuild the Objective Toolkit library in the needed configurations.