2014-11-25 52 views
4

我無法在我的VS2012 MFC C++項目(在Win7上)中使用GDI + 1.1類。類圖像,位圖,圖形工作得很好,但當我嘗試聲明Blur類(或其他v1.1類)的對象時,我得到一個error C2065: ‘Blur’: undeclared identifier。我試圖定義GDIPVER(Stdafx.h中)這樣如何在MFC項目中打開GDI + 1.1而不是1.0?

#define GDIPVER 0x0110 //also I get the warning C4005: 'GDIPVER' : macro redefinition 
#include <gdiplus.h> 
#pragma comment (lib,"Gdiplus.lib") 

,但它不工作。

如何打開GDI + 1.1而不是1.0?

+1

redef警告是壞的。 *在你做之前,一些*代碼是#including gdiplus.h。最好的地方在於你的stdafx.h文件。用/ showIncludes排除故障 – 2014-11-25 12:37:43

+0

是的,這是在我的stdafx.h中的最後 – Craftsmann 2014-11-25 12:39:49

+0

也許以前的東西也包括它。 – doctorlove 2014-11-25 12:49:14

回答

2

我在一個項目上爭論了一段時間的類似問題。對於我來說,我的預編譯頭具有這樣的:

#define GDIPVER  0x0110 // Use more advanced GDI+ features 

但預編譯的頭不會#包括「gdiplus.h」。這隻發生在實際進行GDI +調用的.cpp文件中。我轉發爲GDI +對象指針作爲成員的頭聲明GDI +類。正如漢斯和其他評論指出的那樣,在設置GDIPVER之前,可能會有另一個頭文件,包括gdiplus.h。要確定它包含在哪裏,請嘗試進入項目的C/C++>命令行設置並添加/ showIncludes,然後執行完整構建並查看構建日誌中的gdiplus.h並追蹤到包含它的第一個標題。

一旦你清除了障礙,我還發現我的應用程序實際上並不使用1.1功能,除非清單也被更新。所以我的一個.cpp文件有這個:

// Update Manifest 
// cf: http://blogs.msdn.com/b/oldnewthing/archive/2007/05/31/2995284.aspx 
// 
// We use features from GDI+ v1.1 which is new as of Windows Vista. There is no redistributable for Windows XP. 
// This adds information to the .exe manifest to force GDI+ 1.1 version of gdiplus.dll to be loaded on Vista 
// without this, Vista defaults to loading version 1.0 and our application will fail to launch with missing entry points. 
#if 64BIT_BUILD 
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 
#else 
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"") 
#endif 
+1

/showIncludes選項非常有用。因此,我發現前面已經包含了gdiplus.h。我刪除了'#include '和'#pragma comment(lib,「Gdiplus.lib」)'並且在stdafx.h的開頭放了'#define GDIPVER 0x0110'。現在它工作了! – Craftsmann 2014-11-25 14:40:08

+0

對不起喚醒一個老問題,但我可以建議你使用'*'而不是'amd64'或'x86'?它更簡單。 – LHLaurini 2016-01-15 17:56:12

+0

我相當肯定我已經嘗試過,但它失敗了,但如果它適合你,這是一個好方法。 – jschroedl 2016-01-15 18:17:41

相關問題