David David - 1 year ago 125
C Question

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];

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

#ifdef Polygon
#undef Polygon

Didn't help..

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download