2012-02-06 124 views
0

我想使用CDatabase,并且我已经在stdafx.h文件中声明<afxdb.h>。 当我编译此代码时,出现错误“WINDOWS.H已包含在内,MFC应用程序不能为#include <windows.h>”。为什么会发生?这不是正确的头文件使用CDatabase? 这是默认生成的代码...错误声明<afxdb.h>里面stdafx.h

#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后>,我得到指定的错误。

谢谢

+0

可以举一些例子代码?看起来像你尝试加载多次你的头文件。看看http://stackoverflow.com/q/2939368/1141095 – ezdazuzena 2012-02-06 09:47:15

+0

也许更有组织?你可以改变你的问题,并把代码放在那里。请记住,人们可能只会获得您提供的信息。 – ezdazuzena 2012-02-06 10:00:39

回答

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,你可能会改变项目属性 - >常规 - >从Use Standard Windows LibrariesUse MFC in a Static Library所以使用MFC该链接器是满意的,并不打扰你与未解决的外部符号错误。

希望这有助于;)

+0

伟大..这工程。但是在我声明一个CDatabase对象后,我得到了一些奇怪的错误。 ** 1:)无法解析的外部符号__endthreadex 2:)无法解析的外部符号__beginthreadex **任何想法可能是什么? – digvijay 2012-02-06 10:43:47

+0

项目属性 - >常规 - >使用MFC:更改'使用标准Windows库'以'在静态库中使用MFC' – LihO 2012-02-06 10:45:25

+0

非常感谢。有用。如果你不介意,你能向我解释一下这个变化如何影响它吗?我是这个新手 – digvijay 2012-02-06 10:49:56

0

您需要先#包括AFX-头。之后,你可能仍然#include <windows.h>,虽然这不是必要的。所以只要改变你的包装的顺序,它就会起作用。

+0

伟大..这工作。但是在我声明一个CDatabase对象后,我得到了一些奇怪的错误。 ** 1:)无法解析的外部符号__endthreadex ** ** 2:)无法解析的外部符号__beginthreadex ** 任何想法可能是什么? – digvijay 2012-02-06 10:39:35