0

我正在尝试使用 CDatabase,为此我已<afxdb.h>在 stdafx.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 <afxdb.h>之后添加,#include <tchar.h我会得到指定的错误。

谢谢你

4

2 回答 2

0

您需要首先#include afx-headers。之后,您可能仍然#include <windows.h>,尽管这不是必需的。因此,只需更改包含的顺序,它就会起作用。

于 2012-02-06T10:22:33.737 回答
0

只需添加这些行:

#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 LibrariesUse MFC in a Static Library使链接器满意并且不会因未解决的外部符号错误而困扰您。

希望这可以帮助 ;)

于 2012-02-06T10:29:35.123 回答