I\'m trying to include the following definitions for GDI+ into my Win32 C++ project that is compiled under Visual Studio 2017:
#include
#include
There's a way to get this to work if you're prepared to edit the Windows header files.
In objbase.h
, comment out line 239 or change it to:
static_assert (std::is_base_of <IUnknown *, *pp>::value, "pp must derive from IUnknown");
In gdiplusheaders.h
, line 891, remove the redundant qualifier (Metafile::
).
In gdiplusstringformat.h
, line 220, remove the redundant qualifier (StringFormat::
).
Hopefully, that will fix things for you without breaking anything.
Add this line before the very first(!) #include
of COM-related header to fix objbase.h(239): error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'
:
typedef struct IUnknown IUnknown;
This fix works, because the line in objbase.h(239)
mentioned in the error contains static_cast<IUnknown*>(*pp);
despite that IUnknown still haven't been declared in that place.
I kinda got it to compile, but this is definitely not a good solution. I'm posting it here as a temp workaround until Microsoft gets their heads out of their ___es. Also if anyone finds a better way, please let me know.
I basically had to downgrade the entire project to Visual Studio 2015 - Windows XP (v140_xp)
just to compile one badly written library:
This created a problem of its own with the std
libraries:
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cstdio(50): error C4995: 'sprintf': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cstdio(53): error C4995: 'vsprintf': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cstring(20): error C4995: 'strcat': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cstring(21): error C4995: 'strcpy': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cwchar(29): error C4995: 'swprintf': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cwchar(30): error C4995: 'vswprintf': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cwchar(32): error C4995: 'wcscat': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cwchar(34): error C4995: 'wcscpy': name was marked as #pragma deprecated
So I had to shunt those errors of unsafe functions:
#pragma warning( push )
#pragma warning( disable: 4995 )
#include <stdio.h>
#include <new>
#include <string>
#pragma warning( pop )
Which is far from ideal!
(You're basically sacrificing security of the app just to compile that damn GDI+ library.)