2012-02-06 121 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