5
votes

I unable to use GDI+ 1.1 classes in my VS2012 MFC C++ project (on Win7). Classes Image, Bitmap, Graphics works just fine but when I try to declare an object of Blur class (or other v1.1 classes) I am getting an error C2065: ‘Blur’: undeclared identifier. I tried to define GDIPVER (in stdafx.h) like this

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

but it does not work.

How to turn on GDI+ 1.1 instead of 1.0?

2
The redef warning is bad. Some code is #including gdiplus.h before you do. Best place for this is in your stdafx.h file. Troubleshoot with /showIncludesHans Passant
Yes, this is in my stdafx.h at the very end of itCraftsmann
Perhaps something before is including it too.doctorlove
I checked once again. stdafx.h is the only one place where gdiplus.h is mentioned throughout solution.Craftsmann
Maybe something else not in your solution you are including is including the file.Erbureth

2 Answers

5
votes

I fought with a similar issue for a while on one project. For me, my precompiled header has this:

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

but the precompiled header does not #include "gdiplus.h". That only occurs in the .cpp files which actually make GDI+ calls. I forward declare GDI+ classes for the headers which have GDI+ object pointers as members. As Hans and other comments noted, there's probably another header including gdiplus.h before the GDIPVER is set. To figure out where it's included try going to the C/C++ > Command Line settings for your project and add /showIncludes then do a full build and look in the build log for gdiplus.h and track back to the first header including it.

Once you clear that hurdle, I also discovered my application would not actually use the 1.1 features unless the manifest was also updated. So one of my .cpp files has this:

// 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
0
votes

FWIW, I did the following to enable GDI+ 1.1 in a VS 2019 MFC project:

  1. Added this line in pch.cpp before including pch.h:
    #define GDIPVER 0x0110
  2. Added these lines in pch.h after including framework.h:
    #include <gdiplus.h>
    using namespace Gdiplus;
  3. Used a slightly modified and updated version of the code block kindly provided by @jschroedl 7 (!) years ago:
// Update Manifest
// cf: http://blogs.msdn.com/b/oldnewthing/archive/2007/05/31/2995284.aspx
//
// We use features from GDI+ v1.1 which was new as of Windows Vista. There is no redistributable for Windows XP.
// This adds information to the .exe manifest to force the GDI+ 1.1 version of gdiplus.dll to be loaded.
// Without this, Windows will load the GDI+ 1.0 version of gdiplus.dll and the application will fail to launch with missing entry points.
#ifdef _WIN64
    //#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

I instantiated a Blur object in my startup code to verify I was compiling against GDI+ 1.1 and scoping it so it would be destroyed before calling GdiplusShutdown(), and the app ran and shut down correctly in both x86 and x64 builds.