Porting from visual studio 2005 to 2015 RRS feed

  • Question

  • I am porting an mfc application from VS 2005 to VS 2015. I simply upgraded by opening the application in VS 2015. It built successfully with some minor changes. I am facing a Problem during runtime. The mainframe class OnCreate method Fails. It simply Returns without creating a mainframe handle. I also observed that in VS 2005 the mainframe is inherited from CMDIFrameWnd class while in VS2015 it is inherited from CMDIFrameWndEx class. I have changed that and tried as well but still the same error. Has someone else also faced a similar Problem? Can anyone direct me to the possible error and fix for the same?
    • Edited by BhushanS7 Monday, September 16, 2019 8:38 AM
    Monday, September 16, 2019 8:37 AM

All replies

  • I used VS2005 to create an MFC MDI application and accepted all the wizard defaults.  Then I used VS2015 to open the VS2005 Solution.  It upgraded as expected.  VS2015 was able to build the project and it executed successfully without any changes to the source code -

    So I suggest you build your own project in VS2015 after setting the project options to use MFC in a static lib.  That will enable you to use the debugger to step through the code that runs during the creation of the main frame window to determine the reason that window creation fails.

    Monday, September 16, 2019 9:30 AM
  • Hello,

    Thank you for posting here.

    >> The mainframe class OnCreate method Fails. It simply Returns without creating a mainframe handle.

    The mainframe handle creation is in the initialization function of APP, not in the OnCreate function of mainframe, as shown in the code below. You need to describe your errors in detail so that we can give you better advice.

    BOOL CMFCApplication5App::InitInstance()
    	// InitCommonControlsEx() is required on Windows XP if an application
    	// manifest specifies use of ComCtl32.dll version 6 or later to enable
    	// visual styles.  Otherwise, any window creation will fail.
    	InitCtrls.dwSize = sizeof(InitCtrls);
    	// Set this to include all the common control classes you want to use
    	// in your application.
    	InitCtrls.dwICC = ICC_WIN95_CLASSES;
    	// Initialize OLE libraries
    	if (!AfxOleInit())
    		return FALSE;
    	// AfxInitRichEdit2() is required to use RichEdit control
    	// AfxInitRichEdit2();
    	// Standard initialization
    	// If you are not using these features and wish to reduce the size
    	// of your final executable, you should remove from the following
    	// the specific initialization routines you do not need
    	// Change the registry key under which our settings are stored
    	// TODO: You should modify this string to be something appropriate
    	// such as the name of your company or organization
    	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
    	LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)
    	// Register the application's document templates.  Document templates
    	//  serve as the connection between documents, frame windows and views
    	CMultiDocTemplate* pDocTemplate;
    	pDocTemplate = new CMultiDocTemplate(IDR_MFCApplication5TYPE,
    		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    	if (!pDocTemplate)
    		return FALSE;
    	// create main MDI Frame window
    	CMainFrame* pMainFrame = new CMainFrame;
    	if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
    		delete pMainFrame;
    		return FALSE;
    	m_pMainWnd = pMainFrame;
    	// Parse command line for standard shell commands, DDE, file open
    	CCommandLineInfo cmdInfo;
    	// Dispatch commands specified on the command line.  Will return FALSE if
    	// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
    	if (!ProcessShellCommand(cmdInfo))
    		return FALSE;
    	// The main window has been initialized, so show and update it
    	return TRUE;

    >>I also observed that in VS 2005 the mainframe is inherited from CMDIFrameWnd class while in VS2015 it is inherited from CMDIFrameWndEx class. 

    It has no effect with your error. It's just that MFC extends some functions. When you create MFC, change the project style to standard. The mainframe will be inherited from CMDIFrameWnd class.

    If you're confused about this, choose the standard style to create the project and start your programming. 

    Best Regards,

    Suarez Zhou

    Tuesday, September 17, 2019 3:07 AM
  • Hello,

    Do you resolve the issue? If you resolve the issue, could you please mark the helpful as answer. it will be beneficial to other community.

    Best Regards,

    Suarez Zhou

    Thursday, September 19, 2019 1:48 AM