错误提示:unresolved external symbol __endthreadex

来源:互联网 发布:淘宝指导开店是真是假 编辑:程序博客网 时间:2024/06/08 11:16

第一个MFC应用程序创建简单的Hello窗口遇到的问题。

错误代码:

//Hello.h
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();

};

class CMainWindow : public CFrameWnd
{
public:
CMainWindow();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP();

};

//Hello.cpp
#include <afxwin.h>
#include "Hello.h"

CMyApp myApp;

//CMyApp member fuctions

BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd ->ShowWindow(m_nCmdShow);
m_pMainWnd ->UpdateWindow();
return TRUE;
}

BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP


CMainWindow::CMainWindow()
{
Create(NULL, _T("The Hello Application"));

}

void CMainWindow::OnPaint()
{
CPaintDC dc (this);
CRect rect;
GetClientRect(&rect);
dc.DrawText(_T("Hello,MFC"), -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);

}

改正后的代码:

//Hello.h
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();

};

class CMainWindow : public CFrameWnd
{
public:
CMainWindow();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP() //此处不可以加";"分号很多时候都容易忘记而习惯地加上了";"

};

//Hello.cpp
#include <afxwin.h>
#include "Hello.h"

CMyApp myApp;

//CMyApp member fuctions

BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd ->ShowWindow(m_nCmdShow);
m_pMainWnd ->UpdateWindow();
return TRUE;
}

BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP //此处忘记加()


CMainWindow::CMainWindow()
{
Create(NULL, _T("The Hello Application"));

}

void CMainWindow::OnPaint()
{
CPaintDC dc (this);
CRect rect;
GetClientRect(&rect);
dc.DrawText(_T("Hello,MFC"), -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);

}

运行后仍提示的错误:

inking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/Hello.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.Hello.exe - 3 error(s), 0 warning(s)
解决方法:将工程设置为Using MFC in a static library

编译运行结果:

如上错误主要是因为MFC类库没有引用所出现的问题。

具体解决方法:选择Project 然后选择Setings再选择General 在Microsoft foundation Classes 下拉列表中有三个选项:1.Not using MFC 2. Use MFC in a Static Libray 3. Use MFC in a Shared DLL 这里选择第2个就可以了。

原创粉丝点击