发出调试MFC应用程序,构建但未运行

时间:2016-04-29 11:03:14

标签: c++ mfc

我成功构建了代码,但它没有调试,并在向导杂项代码中提出此警告。

"Warning: Destroying non-NULL m_pMainWnd\n" 

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

这样做的目的是创建一个对话框,允许用户输入汽车规格和轨道,以便计算单圈时间。

主要对话框的源文件:

#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();
};

主要对话框的源文件:

// 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()
};

源文件:向导写的appmodule.cpp

// 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

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

源文件 - 提示警告的向导代码:

// 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;
}

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

1 个答案:

答案 0 :(得分:1)

(请参阅我对此问题的答案:Cannot create main window?,它与您的问题非常相似)

如果您使用向导创建了此项目,那么您还应该拥有CWinApp实现的源文件。如果它的其他类型的向导生成应用程序,那么你仍然应该有一个类似InitInstance的方法。以下代码行:

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

(我假设LapTimeSim是你的主要入口对话框)。如果删除上面的行,您将获得与描述中完全相同的跟踪和行为(我在本地检查过)。

因此,您应该检查是否错误地删除了它们,或者从MFC模板向导重新创建项目。