MFC application works in Visual Studio but crashes with double click launch

911 views Asked by At

I have a GUI application in MFC. For some reason, it works perfectly fine within Visual Studio Release and Debug mode, but crashes if the .exe is launched with a double click.

I cannot understand where this error could be, since it works perfectly fine when hosted in Visual Studio. In desperation, I disabled all Optimization routines but it does not seem to have helped.

OS is Win 7,IDE is VS 2010.

The faulting module is ntdll.dll, but I doubt it is the real issue...

EDIT -

Attaching the debugger to the crash shows a problem with LoadFrame()

BOOL CAAUserInterfaceDllConsumerApp::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.
    INITCOMMONCONTROLSEX InitCtrls;
    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;
    InitCommonControlsEx(&InitCtrls);

    CWinAppEx::InitInstance();


    EnableTaskbarInteraction(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"));

    DWORD isApprunning = 0;

    m_hStartMutex = CreateSemaphore(NULL,
                                    1,
                                    1,
                                    _T("Something"));

    if (GetLastError() ==  ERROR_ALREADY_EXISTS)
    {
        // I dont want to start !
        return FALSE;
    }

    InitContextMenuManager();

    InitKeyboardManager();

    InitTooltipManager();
    CMFCToolTipInfo ttParams;
    ttParams.m_bVislManagerTheme = TRUE;
    theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
        RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);

    // To create the main window, this code creates a new frame window
    // object and then sets it as the application's main window object
    CMainFrame* pFrame = new CMainFrame;
    if (!pFrame)
        return FALSE;
    m_pMainWnd = pFrame;
    // create and load the frame with its resources
    pFrame->LoadFrame(IDR_MAINFRAME,
        WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
        NULL);
      .//more stuff
}

This calls :

BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) 
{
    // base class does the real work

    //if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
    if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
    {
        return FALSE;
    }

And here is where it fails outside of Visual Studio.

The Exception given is : The activation context being deactivated is not the most recently activated one.

I searched around and tried the following, i.e., set all Exceptions to throw to catch any handled exception, and setting afxAmbientActCtx to FALSE, but no luck getting it to run. This exe used to run just fine before.

Kindly advise.

0

There are 0 answers