MFC 错误 error C2504、error C1189
error C2504: “CDialogEx”: 未定义基类-报错解决
在MFC文件中添加资源窗口,后添加新类,随后在.h头文件中出现 CDialogEx C++ class 未定义基类错误。
解决:一般添加#include <afxdialogex.h>
头文件就可以解决,还不行的话请看下面其他的解决方法。
报错原因
首先,上图这个framework.h非常关键,它在pch.h中也有定义,所以下图这个framework.h可以删掉,但是pch.h中的framework.h不能删除,否则必报类似CDialogEx C++ class 未定义基类的错误。
如果你把framework.h中如下语句删除,报错:
#include <afxcontrolbars.h> // MFC 支持功能区和控制条
在afxcontrolbars.h头文件中有afxdialogex.h头文件,该头文件中定义了基类CDialogEx:
问题解决方法:
-
添加
#include <afxdialogex.h>
#include <windows.h>
均不行 -
添加
#include <afx.h>
#include <windows.h>
均不行 -
添加了
#include <afxwin.h>
也不行 -
添加以下代码:
#include <afxcontrolbars.h>
成功!
————————————————
版权声明:本文为CSDN博主「Pvr1sC」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_51911432/article/details/122816079
## 错误 error C1189
如果新建一个Win32控制台应用程序,应用程序设置里附加选项勾选了"预编译头",但是程序里使用了CString等MFC框架中的类型的话,编译报错,在stdafx.h中添加MFC框架程序需要的头文件:
#pragma once
#include <stdio.h>
#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料
#endif
#include <afx.h>
#include <afxwin.h> // MFC 核心组件和标准组件
#include <afxext.h> // MFC 扩展
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC 对 Internet Explorer 4 公共控件的支持
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC 对 Windows 公共控件的支持
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <iostream>
#include <atlbase.h>
#include <atlstr.h>
编译后如果报如下错误的话:
Building MFC application with /MD[d] (CRT dll version) requires MFC share dll version.Please #define _AFXDLL or do not use /MD[d]
解决方法:在stdafx.h头文件中添加#define _AFXDLL
即可。