简单显示窗口程序给出错误VS2012

时间:2014-07-18 16:19:14

标签: c++ windows mfc

#include<afxwin.h>
#include"stdafx.h"

class CSimpleFrame : public CFrameWnd
{
    public:
    CSimpleFrame()
    {
        Create(NULL,L"Windows Application");
    }       

};

struct CSimpleApp : public CWinApp
{
     BOOL InitInstance()
    {
        CSimpleFrame *Tester= new CSimpleFrame();
        m_pMainWnd=Tester;

        m_pMainWnd->ShowWindow(SW_SHOW);
        m_pMainWnd->UpdateWindow();

        return TRUE;
    }


};

CSimpleApp theApp;

该程序用于在vs2012中显示一个简单的窗口。 显然,我是Windows编程的新手。也是在我创建了全局对象theApp之后,这个错误就开始了。

我得到的错误如下。

    Debug Assertion Failed!
    Program: C:\Windows\system32\mfc110ud.dll
    File: f:\\dd\vctools\vc7libs\ship\atlmfc\src\mfc\appcore.cpp
    Line: 196

    **line 196 of appcore.cpp is**
    ASSERT(AfxGetThread() == NULL);
    When this error is shown i press retry.And then i press break and then continue then it gives another error
    Debug Assertion Failed!
    Program: C:\Windows\system32\mfc110ud.dll
    File: f:\\dd\vctools\vc7libs\ship\atlmfc\src\mfc\appcore.cpp
    Line: 203

    **line 203 of appcore.cpp is** 
    ASSERT(afxCurrentWinApp == NULL); // only one CWinApp object please

1 个答案:

答案 0 :(得分:0)

我得到了同样的错误并以这种方式解决了我的问题。如果有人遇到同样的问题,你可以使用这个解决方案。

MFC编程中的这些问题通常在未正确设置项目设置时发生。 转到项目设置&gt;链接器&gt;系统

在子系统中选择:(/ SUBSYSTEM:WINDOWS)

这应该可以解决问题。