Search code examples
cwindowsredefinition

Redefinition error in c


I have to include "windows.h".The problem is redefinition, In windows.h:

_gdi_entry WINGDIAPI BOOL  WINAPI Polygon(__in HDC hdc, __in_ecount(cpt)
                                            CONST POINT *apt, __in int cpt);

Part of my code is(comes from other include):

typedef struct Polygon
{
    U8 numElements;
    PolygonPoints element[15];    
}Polygon;

I can't change the definition in my code. I am including windows.h for ShellExecute(). Tried to undef:

#ifdef Polygon 
#undef Polygon
#endif

Didn't help..

EDIT: Solved the problem with rodrigo's answer.


Solution

  • The #undef Polygon won't work because Polygon() is a real function, not a macro. In Windows, that trick mostly works for functions that takes at least one string argument, because of the Unicode vs ANSI stuff.

    If you only want the ShellExecute() function you can omit all the GDI functions by defining NOGDI before including Windows.h:

    #define NOGDI
    #include <windows.h>
    

    Alternatively you can add the NOGDI macro to the preprocessor project options of your IDE.