GDI+ library causes “error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'” in VS2017 when compiled for XP

前端 未结 3 1178
南旧
南旧 2021-01-22 01:48

I\'m trying to include the following definitions for GDI+ into my Win32 C++ project that is compiled under Visual Studio 2017:

#include 
#include         


        
相关标签:
3条回答
  • 2021-01-22 02:25

    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.

    0 讨论(0)
  • 2021-01-22 02:29

    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.

    0 讨论(0)
  • 2021-01-22 02:39

    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.)

    0 讨论(0)
提交回复
热议问题