diff --git a/include/wx/defs.h b/include/wx/defs.h index cc07065a7d..19a22cc39d 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -10,6 +10,31 @@ /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */ +/* + We want to avoid compilation and, even more perniciously, link errors if + the user code includes before include wxWidgets headers. These + error happen because #define's many common symbols, such as + Yield or GetClassInfo, which are also used in wxWidgets API. Including our + "cleanup" header below un-#defines them to fix this. + + Moreover, notice that it is also possible for the user code to include some + wx header (this including wx/defs.h), then include and then + include another wx header. To avoid the problem for the second header + inclusion, we must include wx/msw/winundef.h from here always and not just + during the first inclusion, so it has to be outside of _WX_DEFS_H_ guard + check below. + */ +#ifdef __cplusplus + /* + Test for WIN32, defined by windows.h itself, not our own __WINDOWS__, + which is not defined yet. + */ +# ifdef WIN32 +# include "wx/msw/winundef.h" +# endif /* WIN32 */ +#endif /* __cplusplus */ + + #ifndef _WX_DEFS_H_ #define _WX_DEFS_H_ @@ -3294,16 +3319,6 @@ typedef const void* WXWidget; #include "wx/qt/defs.h" #endif -/* This is required because of clashing macros in windows.h, which may be */ -/* included before or after wxWidgets classes, and therefore must be */ -/* disabled here before any significant wxWidgets headers are included. */ -#ifdef __cplusplus -#ifdef __WINDOWS__ -#include "wx/msw/winundef.h" -#endif /* __WINDOWS__ */ -#endif /* __cplusplus */ - - /* include the feature test macros */ #include "wx/features.h"