简体   繁体   中英

Issue debugging an MFC applicaiton, building but not running

I build the code successfully but it does not debug and comes up with this warning in a wizard miscellaneous code.

"Warning: Destroying non-NULL m_pMainWnd\n" 

and

"Warning: Temp map lock count non-zero (%ld).\n",

The aim of this is to create a dialog box that allows a user to input car specifications and a track so a lap time can be calculated.

Source File of Main Dialogue box:

#define _WIN32_WINNT 0x0601
// LapTimeSim.cpp : implementation file
//
#include <iostream>
#include "stdafx.h"
#include "LapTimeSim.h"
#include "afxdialogex.h"
#include "SecondDlg.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
using namespace std;

// LapTimeSim dialog

 IMPLEMENT_DYNAMIC(LapTimeSim, CDialogEx);



 LapTimeSim::LapTimeSim(CWnd* pParent /*=NULL*/)
     : CDialogEx(IDD_DIALOG1, pParent)
{

}

LapTimeSim::~LapTimeSim()
{
}

void LapTimeSim::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(LapTimeSim, CDialogEx)
    ON_BN_CLICKED(IDC_CAR, &LapTimeSim::OnBnClickedCar)
    ON_BN_CLICKED(IDGO, &LapTimeSim::OnBnClickedGo)
    ON_BN_CLICKED(IDC_TRACK, &LapTimeSim::OnBnClickedTrack)
END_MESSAGE_MAP()


// LapTimeSim message handlers


void LapTimeSim::OnBnClickedCar()
{
    // TODO: Add your control notification handler code here
    CSecondDlg Dlg;

    Dlg.DoModal();

}


void LapTimeSim::OnBnClickedGo()
{
     // TODO: Add your control notification handler code here
}




void LapTimeSim::OnBnClickedTrack()
{
    // TODO: Add your control notification handler code here
}


 A Large Header; Header file of main dialog box
==============

#pragma once


// LapTimeSim dialog

class LapTimeSim : public CDialogEx
 {
    DECLARE_DYNAMIC(LapTimeSim)

 public:
    LapTimeSim(CWnd* pParent = NULL);   // standard constructor
    virtual ~LapTimeSim();

// Dialog Data
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_DIALOG1 };
    #endif

 protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

    DECLARE_MESSAGE_MAP()
public:
    afx_msg void OnBnClickedCar();
    afx_msg void OnBnClickedGo();
    afx_msg void OnBnClickedTrack();
};

Source File of Main Dialogue box:

// SecondDlg.cpp : implementation file
//
#define _WIN32_WINNT 0x0601
#include <iostream>
#include "stdafx.h"
#include "LapTimeSim.h"
#include "afxdialogex.h"
#include "SecondDlg.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CSecondDlg dialog

IMPLEMENT_DYNAMIC(CSecondDlg, CDialog)

CSecondDlg::CSecondDlg(CWnd* pParent /*=NULL*/)
    : CDialog(IDD_DIALOG2, pParent)
{

}

CSecondDlg::~CSecondDlg()
{
}

void CSecondDlg::DoDataExchange(CDataExchange* pDX)
{
   CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSecondDlg, CDialog)
END_MESSAGE_MAP()


// CSecondDlg message handlers



 A Large Header; Header file of second dialog box
==============
#pragma once


// CSecondDlg dialog

class CSecondDlg : public CDialog
{
    DECLARE_DYNAMIC(CSecondDlg)

public:
    CSecondDlg(CWnd* pParent = NULL);       // standard constructor
    virtual ~CSecondDlg();

// Dialog Data
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_DIALOG2 };
#endif

protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

    DECLARE_MESSAGE_MAP()
};

Source File : appmodule.cpp writeen by the wizard

// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#include "stdafx.h"
#include "sal.h"

/////////////////////////////////////////////////////////////////////////////
// export WinMain to force linkage to this module
extern int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    _In_ LPTSTR lpCmdLine, int nCmdShow);

extern "C" int WINAPI
_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    _In_ LPTSTR lpCmdLine, int nCmdShow)
 #pragma warning(suppress: 4985)
{
    // call shared/exported WinMain
    return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}

/////////////////////////////////////////////////////////////////////////////
// initialize app state such that it points to this module's core state

BOOL AFXAPI AfxInitialize(BOOL bDLL, DWORD dwVersion)
{
    AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
     pModuleState->m_bDLL = (BYTE)bDLL;
    ASSERT(dwVersion <= _MFC_VER);
    UNUSED(dwVersion);  // not used in release build
#ifdef _AFXDLL
    pModuleState->m_dwVersion = dwVersion;
 #endif
 #ifdef _MBCS
    // set correct multi-byte code-page for Win32 apps
    if (!bDLL)
        _setmbcp(_MB_CP_ANSI);
#endif //_MBCS
     return TRUE;
}

// force initialization early
#pragma warning(disable: 4074)
#pragma init_seg(lib)

#ifndef _AFXDLL
void AFX_CDECL _AfxTermAppState()
{
    // terminate local data and critical sections
    AfxTermLocalData(NULL, TRUE);
    AfxCriticalTerm();

     // release the reference to thread local storage data
    AfxTlsRelease();
}
#endif

#ifndef _AFXDLL
char _afxInitAppState = (char)(AfxInitialize(FALSE, _MFC_VER),              atexit(&_AfxTermAppState));
#else
char _afxInitAppState = (char)(AfxInitialize(FALSE, _MFC_VER));
#endif

  /////////////////////////////////////////////////////////////////////////////

Source File - Wizard code coming up with warning:

// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
 // See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#include "stdafx.h"
#include "sal.h"


/////////////////////////////////////////////////////////////////////////////
// Standard WinMain implementation
//  Can be replaced as long as 'AfxWinInit' is called first

    int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    _In_ LPTSTR lpCmdLine, int nCmdShow)
 {
    ASSERT(hPrevInstance == NULL);

    int nReturnCode = -1;
    CWinThread* pThread = AfxGetThread();
    CWinApp* pApp = AfxGetApp();

    // AFX internal initialization
    if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
        goto InitFailure;

    // App global initializations (rare)
    if (pApp != NULL && !pApp->InitApplication())
        goto InitFailure;

    // Perform specific initializations
    if (!pThread->InitInstance())
    {
        if (pThread->m_pMainWnd != NULL)
            {
            TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n");
        pThread->m_pMainWnd->DestroyWindow();
    }
    nReturnCode = pThread->ExitInstance();
    goto InitFailure;
}
nReturnCode = pThread->Run();

InitFailure:
#ifdef _DEBUG
// Check for missing AfxLockTempMap calls
if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
{
    TRACE(traceAppMsg, 0, "Warning: Temp map lock count non-zero (%ld).\n",
        AfxGetModuleThreadState()->m_nTempMapLock);
}
AfxLockTempMaps();
AfxUnlockTempMaps(-1);
#endif

AfxWinTerm();
return nReturnCode;
}

/////////////////////////////////////////////////////////////////////////////

(See my answer to this SO: Cannot create main window? , it looks very similar to your issue)

If you have created this project with wizard then you should also have source files for CWinApp implementation. If its some other kind of wizard generated application then you still should somewhere have an InitInstance like method. with following lines of code:

LapTimeSim dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();

(I assume here that LapTimeSim is your main entry dialog). If you remove above lines, you will get the exact same trace and behaviour as in your description (I checked this locally).

So you should check if you have by mistake removed them, or recreate project from MFC template wizard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM