Monday, January 3, 2011

Converting Old Visual Studio 8 Projects to VS 9 -- ActiveX controls

While converting an older project to Visual Studio 9 I came across a perplexing situation.  In the initialization of one of the dialogs, an Unhandled Exception : Access Violation was encountered in the mfc90 library source file dlgcore.cpp in the CDialog::HandleInitDialog(WPARAM, LPARAM) function. The problem was when that CWnd function's statement,
m_pCtrlCont->m_pSiteFocus = NULL;, was called m_pCtrlCont was NULL.
After doing some debugging and digging around in CWnd code, I found that
m_pCtrlCont was supposed to be initialized in advance by a call to the MFC function
BOOL CWnd::InitControlContainer(BOOL bCreateFromResource);
because of its use of an ActiveX control. Apparently this is something that didn't always happen in old code but is now a problem. When later built with the new libraries, a window that contained an ActiveX control would cause a crash at run-time.
The fix was simply a matter of adding a call to

InitControlContainer(TRUE); in my ActiveX control containing window's OnCreate event.



No comments:

Post a Comment