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.cppMyApp.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: 在查找预编译头指令时遇到意外的文件结尾------------------------------------
以上就是我遇到的问题,有此想不明白,请大家不吝赐教,谢谢

解决方案 »

  1.   

    myapp.cpp的最前面#include "stdafx.h"其他的所有东西写在这个都后面,不然会出错
      

  2.   

    因为#include "stdafx.h"包含了MFC的库
      

  3.   

    反正你记住,只要是MFC程序需要#include "stdafx.h",这个一定要放在最前面,
    不然会出错。
      

  4.   

    我试了一下,但还是不能运行呀,说文件找不到,不明白了VC6给出的错误提示
    Compiling...
    MyApp.cpp
    c:\c++练习\myapp.cpp(3) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
    Error executing cl.exe.MyApp.exe - 1 error(s), 0 warning(s)我搜了一下,把VC98中的MFC的stdafx.h考到我自己程序的目录中,编译后出现下面的错误提示
    Compiling...
    MyApp.cpp
    c:\c++练习\stdafx.h(112) : fatal error C1083: Cannot open include file: 'afximpl.h': No such file or directory
    Error executing cl.exe.MyApp.obj - 1 error(s), 0 warning(s)怎么样才能让这个程序跑起来呀?问题出在哪儿
      

  5.   

    项目->属性->c++ ->代码生成->运行时库选择多线程调试