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

时间:2015-07-16 14:42:03

标签: c++ visual-studio-2010 mfc

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

在尝试编译类时,我收到了错误:

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

在我的解决方案中: 属性 - >一般我在共享DLL中使用MFC(我也试过静态链接) 一般 - > Charater set:使用多字节字符集 C / C ++ - >预编译的标题 - >使用

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>

问题类的头文件

// blocksock.h

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

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

包含.cpp类的.cpp

#include "stdafx.h"
#include "blocksock.h"

要显示的第一个标题是:

\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文件,但似乎无法识别在其中定义的类。

注意:我刚尝试换到

一般 - &gt; Charater set:使用Unicode字符集

因为我注意到afx.h中有关基于wchar_t的评论

而不是上面的错误getloads of errors about 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'

2 个答案:

答案 0 :(得分:1)

我有类似的问题,我认为在这种情况下更好的方法是创建一个新的MFC项目,并迁移文件。看起来像一个大工作,但你会浪费更少的时间,而不是试图解决每个依赖问题。

答案 1 :(得分:1)

向我这样的人发帖,他们在这个帖子中找不到答案,这里有额外的信息可以帮到你。

我遇到了类似的问题,我在.h和.cpp中都包含stdafx.h,更新了Visual Studio Service Pack 1并确保我的所有项目“使用MFC”都设置为“使用MFC”在共享DLL“(在Properies / Configuration Properties / General中)

如果您没有尝试过上述三种解决方案中的任何一种,请尝试一下。