// 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 functionBOOL CMyApp::InitInstance()
{
m_pMainWnd=new CMainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}///////////////////////////////////////////////////////////////////////////
//CMainWindow message map and member functionsBEGIN_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);
}-------------------------------------------------------------------------------------
我调试的错误如下:
--------------------Configuration: Hello - Win32 Debug--------------------
Linking...
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)
各位大虾帮我看看,这个程序哪里错了?

解决方案 »

  1.   

    http://www.china-askpro.com/msg3/qa67.shtml
      

  2.   

    不要照抄书上的代码,用class wizard生成一个应用程序框架,再看书上是在哪里添加代码的
      

  3.   

    同意  lazio88  的观点,学习vc,类比法很重要的,看看向导生成的代码,再和自己的比比,
    就知道错在哪里了,这是学习vc很重要的方法!!!
      

  4.   

    楼主,你这个问题我也碰到了。现在我把解决的思路给你说一下,希望你能够顺利编译这个工程。
    导致你的Link错误的原因是你建立工程的方法不对,没有使用MFC。具体建立工程的步骤如下:
    1、 File-->New | Projects | Win32 Application(注意是Win32 Application)
    2、在下面填入你的工程目录和名字,如 HelloMFC、 d:\Exercise
    3、接下来,选择建立一个空工程。点确定。
    4、接下来出现工程配置的对话框,点确定。
    5、File->New 添加一个hello.h的文件并填充内容进去:
    //Hello.cpp
    #include <afxwin.h>
    #include "Hello.h"CMyApp myApp;///////////////////////////////////////////////////////////////////////////
    //CMyApp member functionBOOL CMyApp::InitInstance()
    {
    m_pMainWnd=new CMainWindow;
    m_pMainWnd->ShowWindow(m_nCmdShow);
    m_pMainWnd->UpdateWindow();
    return TRUE;
    }6、添加一个 Hello.cpp 文件进去:#include <afxwin.h>
    #include "Hello.h"CMyApp myApp;///////////////////////////////////////////////////////////////////////////
    //CMyApp member functionBOOL CMyApp::InitInstance()
    {
    m_pMainWnd=new CMainWindow;
    m_pMainWnd->ShowWindow(m_nCmdShow);
    m_pMainWnd->UpdateWindow();
    return TRUE;
    }///////////////////////////////////////////////////////////////////////////
    //CMainWindow message map and member functionsBEGIN_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);
    }7.  Project ---> Add to Project -->Files 选择Hello.h , Hello.cpp.
    8.  Project ---> Settings ---> General 页面。
         将 Microsoft Foundation Class 下拉诓的选择项置为: Use MFC in a shared DLL
    9.  OK, F7 Build 整个工程。
    10.  Ctrl + F5 运行!That's all .
      

  5.   

    顺便说一句,其实导致错误的主要原因是 你的工程的 Project-->Settings的 General 页面 没有选择 Use MFC in a shared DLL.