添加类到工程中出现的错误

wilehorse 2003-10-17 05:25:41
把别人的一个打包类加到我的工程中去,出现一个错误:
fatal error C1010: unexpected end of file while looking for precompiled header directive
为什么
该类在例子程序中没有问题
...全文
31 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wilehorse 2003-10-20
  • 打赏
  • 举报
回复
加了#include "stdafx.h"之后,出现52个error,认不得类的定义了,例如:
error C2653: 'ComAccess' : is not a class or namespace name
error C2065: 'm_hCom' : undeclared identifier
error C2065: 'm_lpszErrorMessage' : undeclared identifier

COMACCESSS.h

#ifndef _COMACCESS_H_
#define _COMACCESS_H_


#include <windows.h>


class ComAccess
{
private:

HANDLE m_hCom; // Device handle

OVERLAPPED m_ov; // A structure that contains informations which are
// used for asynchronous input and output operations

TCHAR m_lpszErrorMessage[256];

public:

ComAccess(VOID);
ComAccess(LPCSTR lpszPortNum);

~ComAccess() { Close(); }
// For more definitions see <winbase.h>
BOOL Open(LPCSTR lpszPortNum = "com1",
DWORD dwBaudRate = CBR_9600,
BYTE byParity = NOPARITY,
BYTE byStopBits = ONESTOPBIT,
BYTE byByteSize = 8);

VOID Close(VOID);

DWORD WriteData(LPCVOID pdata, DWORD len);
DWORD ReadData(LPVOID pdest, DWORD len, DWORD dwMaxWait = 500);

LPSTR GetErrorMessage(VOID) { return m_lpszErrorMessage; }

private:

VOID ErrorToString(LPCSTR lpszMessage);

BOOL IsNT(VOID);
};


#endif // _COMACCESS_H_


Goldbach 2003-10-18
  • 打赏
  • 举报
回复
A precompiled header was specified, but it did not contain a precompiled header directive.

This error can be caused by specifying an incorrect file as a header file, or by specifying an include file with the /Yu (Use Precompiled Header) command line option that is not listed in the source file as an include file.

huanyun 2003-10-18
  • 打赏
  • 举报
回复
可以选择 不需要#include "stdafx.h"

有可能有写头文件不能#include "stdafx.h"

在文件上选择Setting->c/c++->precompiled headers->不使用预定义头文件
xushinhwa2003 2003-10-18
  • 打赏
  • 举报
回复
#include "stdafx.h"
yintongshun 2003-10-18
  • 打赏
  • 举报
回复
必须加上#include "stdafx.h"
不过还
有种可能就是你可能是COPY上去的吧,最好写上去或者先COPY到文本文件上再贴上去
csdnzhu 2003-10-18
  • 打赏
  • 举报
回复
fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.
一个工程中如果加入一个.h文件,没有任何关系,如果加入一个.cpp文件就会产生上面的错误,
如果只是一个控制台程序,不会产生以上错误,而MFC程序就会。
如果是一个类,它会占有.h和.cpp文件,那么必须在.cpp中有#include "stdafx.h"语句
  • 打赏
  • 举报
回复
#include "stdafx.h"
linfeng1216 2003-10-18
  • 打赏
  • 举报
回复
很有可能是因为在引入的类头文件中没有 #include "stdafx.h"
Paris_Luo 2003-10-17
  • 打赏
  • 举报
回复
头文件包括了吗
flyingFisher 2003-10-17
  • 打赏
  • 举报
回复
编译没通过啊,会有很多可能的。
是否兼容?
很多东西不能照搬的,最少需要修改下啊

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧