0

I have been converting a large application to MFC feature pack over the last month using Visual Studio 2015. I was finished with development and debugging and ready to create a release build. To my horror, the release build had a severe run-time error which I traced using AfxMessageBoxes to the point in the code where the menu bar is created.

CMFCMenuBar       m_wndMenuBar;

if (!m_wndMenuBar.Create(this))
{
   AfxMessageBox(_T("Failed to create menubar"));
   TRACE0("Failed to create menubar\n");
   return -1;      // fail to create
}

I moved the status bar creation and toolbar creation ahead of the menu bar creation and it still failed at menu bar creation. I turned off optimization in the release build. The debug build works fine.

I have never encountered a release build problem like this before and am at a loss on how to proceed. I could use some advice.

Bob H
  • 135
  • 8
  • Try to step into the menu creation. It somewhat works even in release builds. – Jabberwocky Jun 20 '17 at 20:43
  • 1
    Almost every time I had a 'release crash' problem, the cause ended up being uninitialized variables, or 'parameter count' issues as mentioned in this [article](https://www.codeproject.com/Articles/548/Surviving-the-Release-Version) – Mercury Dime Jun 20 '17 at 21:15
  • I followed Walz's advice and stepped into menu creation. It fails deep, deep in the code in wincore.cpp at cwnd:createx and then tries to get a file called winuser.inl. I will look at the article mentioned by Dime. – Bob H Jun 20 '17 at 22:12
  • Whew. I just tried stepping through code - you weren't kidding about the 'deep, deep' part. I'm in CWnd::CreateEx and it's not badgering me about winuser.inl - I notice there is a call to GetLastError() - you should try calling that in your CMainFrame code - where your AfxMessageBox statement is - `auto errorCode = GetLastError();` On the Tools menu in VStudio there's an error lookup - type the error code in the Value box and it should give you a description for the error. – Mercury Dime Jun 20 '17 at 23:10
  • These bugs are hard to track... It could be something as dumb as an uninitialized variable in your frame window object. Do you use DEBUG_NEW throughout your application? It could also come from a buffer overflow. – Michaël Roy Jun 21 '17 at 02:46
  • @MercuryDime: [CMFCMenuBar::Create](https://learn.microsoft.com/en-us/cpp/mfc/reference/cmfcmenubar-class#create) is not documented to set the last error code. Calling `GetLastError()` is thus meaningless. – IInspectable Jun 21 '17 at 07:37
  • I played around with the project compile and link settings. Amazingly, when I switched from Use MFC in a Static Library to Use MFC in a Shared DLL (which the debug build uses), the release version works. I don't know what this means. – Bob H Jun 21 '17 at 13:07
  • I then rebuilt the debug build using Use MFC in a Static Library and it crashed at ENSURE(strTitle.LoadString(IDS_AFXBARRES_MENU_BAR_TITLE)). I then found a link to my exact issue -- https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/MbFnNPOg7K4 – Bob H Jun 21 '17 at 13:57
  • 1
    That sounds like an issue with managing module state. See [Managing the State Data of MFC Modules](https://learn.microsoft.com/en-us/cpp/mfc/managing-the-state-data-of-mfc-modules) and [TN058: MFC Module State Implementation](https://learn.microsoft.com/en-us/cpp/mfc/tn058-mfc-module-state-implementation) for more details. – IInspectable Jun 21 '17 at 16:15
  • The last time I had a bug that only happened only in Release, it was because I had a statement inside an ASSERT, which of course is not executed in Release. – sergiol Jun 26 '17 at 16:18

0 Answers0