'CObject' : 基础 class 未定义,但我包括 afx.h、afxwin.h e.t.c?

'CObject' : base class undefined but I'm including afx.h, afxwin.h e.t.c?

我正在将大量旧代码转移到我们的新框架工作中,这段旧代码的一部分使用了一些 MFC classes。

尝试编译 class 时出现错误:

error C2504: 'CObject' : base class undefined
error C3861: 'VERIFY': identifier not found
error C3861: 'ASSERT': identifier not found 
....

在我的解决方案中: properties -> General 我在共享 dll 中使用了 MFC(我也试过静态链接) 常规 -> 字符集:使用 Multi-Byte 字符集 C/C++-> 预编译 headers -> 使用

C/C++->高级显示包括 YES

我在所有文件中首先包括 stdafx.h。我在 stdafx.h 中有 afx.h 和 afxwin.h(我尝试了不同的命令,但只包括 afxwin.h)

我的stdafx.h

#pragma once
#include <afx.h>
#include <afxwin.h>   // MFC core and standard components

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>

问题的header文件class

// blocksock.h

#include "stdafx.h"
#include <atlstr.h>

#include "winsock.h"
#include <string>

class

.cpp 的包含
#include "stdafx.h"
#include "blocksock.h"

显示的第一个 header 是:

\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlstr.h

要显示的最后一个包含是:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\share.h

当我查看命令行时,我可以看到它具有 afx.h

的正确路径

我正在使用 VS2010。

这到底是怎么回事!!!它可以看到 MFC 文件,但似乎无法识别其中定义的 class。

注意:我刚试过换到

常规 -> 字符集:使用 Unicode 字符集

因为我注意到 afx.h 中关于基于 wchar_t

的评论

并没有出现上述错误,而是出现了大量关于 MFC 的错误,包括这样的文件。

1>  Note: including file:         C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlalloc.h
1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\atlconv.h(776): error C2440: 'return' : cannot convert from 'LPCTSTR' to 'LPCOLESTR'

我遇到了类似的问题,我认为在这种情况下更好的方法是创建一个新的 MFC 项目,然后迁移文件。看起来像是一项艰巨的工作,但与尝试解决每个依赖性问题相比,你会浪费更少的时间。

发帖给像我一样没有在这个帖子中找到答案的人,这里有一些额外的信息可能会对你有所帮助。

我遇到了类似的问题,我在 .h 和 .cpp 中都包含了 stdafx.h,更新了 Visual Studio 服务包 1 并确保我所有项目的 "Use of MFC"设置为 "Use MFC in a shared DLL"(在 Properies/Configuration Properties/General)

如果您还没有尝试过以上三种解决方案中的任何一种,您应该试一试。