首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

VC.net技术内幕(第六版)中的第一例子,在VC6.0和VS2003中都无法正确运行,这是为什么呢?该怎么解决

2012-01-13 
VC.net技术内幕(第六版)中的第一例子,在VC6.0和VS2003中都无法正确运行,这是为什么呢??VC.net技术内幕(第

VC.net技术内幕(第六版)中的第一例子,在VC6.0和VS2003中都无法正确运行,这是为什么呢??
VC.net技术内幕(第六版)中的第一例子,在VC6.0和VS2003中都无法正确运行,这是为什么呢??
下面给出完整的示例代码和出错信息
-----------------------------
以下是MyApp.h文件内容
class   CMyApp:   public   CWinApp
{
public:
virtual   BOOL   InitInstance();
};

//frame   window   class
class   CMyFrame   :   public   CFrameWnd
{
public:
CMyFrame();
protected:
afx_msg   void   OnLButtonDown(UINT   nFlags,   CPoint   point);
afx_msg   void   OnPaint();
DECLARE_MESSAGE_MAP()
};

---------------------------------------
以下是MyApp.cpp文件内容

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

CMyApp   theApp;

BOOL   CMyApp::InitInstance()
{
m_pMainWnd   =   new   CMyFrame();
m_pMainWnd-> ShowWindow(m_nCmdShow);

m_pMainWnd-> UpdateWindow();
return   TRUE;
}
 
BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
END_MESSAGE_MAP()

CMyFrame::CMyFrame()
{
Create(NULL,   "MYAPP   Application ");
}

void   CMyFrame::OnLButtonDown(UINT   nFlags,   CPoint   point)
{
TRACE( "Entering   CMyFrame::OnLButtonDown   -   %lx,%d,%d\n ",(long)nFlags,point.x,point.y);
}

void   CMyFrame::OnPaint()
{
CPaintDC   dc(this);
dc.TextOut(0,0, "Hello   world! ");
}

------------------------------------
VC   6.0环境中的信息
Compiling...
Skipping...   (no   relevant   changes   detected)
MyApp.cpp

MyApp.obj   -   0   error(s),   0   warning(s)


Linking...
nafxcwd.lib(thrdcore.obj)   :   error   LNK2001:   unresolved   external   symbol   __endthreadex
nafxcwd.lib(thrdcore.obj)   :   error   LNK2001:   unresolved   external   symbol   __beginthreadex
libcd.lib(crt0.obj)   :   error   LNK2001:   unresolved   external   symbol   _main
Debug/MyApp.exe   :   fatal   error   LNK1120:   3   unresolved   externals
Error   executing   link.exe.

MyApp.exe   -   4   error(s),   0   warning(s)

--------------------------------------
VS2003环境中的信息

正在编译...
MyApp.cpp
c:\c++练习\vc2003\myapp.cpp(37)   :   fatal   error   C1010:   在查找预编译头指令时遇到意外的文件结尾

------------------------------------
以上就是我遇到的问题,有此想不明白,请大家不吝赐教,谢谢


[解决办法]
myapp.cpp的最前面#include "stdafx.h "其他的所有东西写在这个都后面,不然会出错
[解决办法]
因为#include "stdafx.h "包含了MFC的库

热点排行