代码之家  ›  专栏  ›  技术社区  ›  Tommy

“CObject”:基类未定义,但我包含afx。h、 afxwin。h e.t.c?

  •  0
  • Tommy  · 技术社区  · 11 年前

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

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

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

    在我的解决方案中: 属性->我在共享dll中使用MFC(我也尝试过静态链接) 常规->字符集:使用多字节字符集 C/C++->预编译的标头->使用

    C/C++->高级表演包括YES

    我包括stdafx。h在所有文件中都是第一位。我有afx。h和afxwin。标准afx中的h。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类的includes

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

    注意:我刚刚尝试切换到

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

    我注意到afx中的一条评论。关于基于wchart

    而不是上面的错误gotloads of errorsabout 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 回复  |  直到 11 年前
        1
  •  1
  •   Montes    11 年前

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

        2
  •  1
  •   MDL    8 年前

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

    我也有类似的问题 stdafx.h 在.h和.cpp中,更新了Visual Studio service pack 1,并确保所有项目的“使用MFC”设置为“在共享DLL中使用MFC”(在“属性/配置属性/常规”中)

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