在 stdafx.h 中声明 <afxdb.h> 时出错
error in declaring <afxdb.h> inside stdafx.h
我正在尝试使用CDatabase,为此我在stdafx.h文件中声明了<afxdb.h>
。当我编译此代码时,我得到一个错误"WINDOWS.H已经包含。MFC应用程序必须不是#include <windows.h>
"。为什么会发生这种情况?这不是使用CDatabase的正确头文件吗?这是默认生成的代码。。。
#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
如果在#include <tchar.h
>之后添加#include <afxdb.h>
,则会得到指定的错误。
谢谢
只需添加以下行:
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> <--
#include <afxext.h> <--
#include <afxdb.h> <--
// Windows Header Files:
#include <windows.h>
但是,由于您以前没有在该项目中使用MFC,您可能需要将项目属性->常规->MFC的使用从Use Standard Windows Libraries
更改为Use MFC in a Static Library
,这样链接器就可以满足要求,并且不会因未解析的外部符号错误而困扰您。
希望这能有所帮助;)
您需要首先#包含afx标头。之后,您可能仍然是#include <windows.h>
,尽管这不是必需的。因此,只要更改包含的顺序,它就会起作用。
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 用pybind11包装C++抽象类时出错
- 为x86而非x64编译时出错
- 从R调用C++函数并对其进行集成时出错
- EASTL矢量<向量<int>>连续的
- 这个函数哪里出错了
- C++ 创建包含链表和字符串的对象的链接列表时出错
- 为重写std::exception的库生成swig接口时出错
- 导入/导出变量时出错