windows.h and #defines in Standard_Macro.hxx

We ran into a compiler error due to a conflict with Open CASCADE headers and another 3rd party component's headers. Specifically the following code in Standard_Macro.hxx caused issues in the other library until I commented these lines out. Can this be moved out of a Standard header in a future release?

# ifdef _WIN32

// We must be careful including windows.h: it is really poisonous stuff!
// The most annoying are #defines of many identifiers that you could use in
// normal code without knowing that Windows has its own knowledge of them...
// So lets protect ourselves by switching OFF as much as possible of this in advance.
// If someone needs more from windows.h, he is encouraged to #undef these symbols
// or include windows.h prior to any OCCT stuff.
// Note that we define each symbol to itself, so that it still can be used
// e.g. as name of variable, method etc.
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN /* exclude extra Windows stuff */
#endif
#ifndef NOMINMAX
#define NOMINMAX NOMINMAX /* avoid #define min() and max() */
#endif
#ifndef NOMSG
#define NOMSG NOMSG /* avoid #define SendMessage etc. */
#endif
#ifndef NODRAWTEXT
#define NODRAWTEXT NODRAWTEXT /* avoid #define DrawText etc. */
#endif
#ifndef NONLS
#define NONLS NONLS /* avoid #define CompareString etc. */
#endif
#ifndef NOGDI
#define NOGDI NOGDI /* avoid #define SetPrinter (winspool.h) etc. */
#endif
#ifndef NOSERVICE
#define NOSERVICE NOSERVICE
#endif
#ifndef NOKERNEL
#define NOKERNEL NOKERNEL
#endif
#ifndef NOUSER
#define NOUSER NOUSER
#endif
#ifndef NOMCX
#define NOMCX NOMCX
#endif
#ifndef NOIME
#define NOIME NOIME
#endif

#endif

Dmitrii Pasukhin's picture

Hello. Thank you for your suggestion. Is it possible to share the 3rd-party name? In case if that information is public, if not - could you just share the more precise the conflict issue? The name of some variables inside external lib dublicats some macroses name?

I will check that possibility to avoid that definition, but needs to know more details.

(I will check the option to move that definition probably on CMake level in case if it require for the OCCT)

Best regards, Dmitrii.

Dmitrii Pasukhin's picture
gkv311 n's picture

The issue with NOMINMAX, WIN32_LEAN_AND_MEAN and other macros is a know mess withwindows.h, and there is no good way to solve it as far as I can see (this is a design issue in windows.h itself, not OCCT). Whatever OCCT headers will define for windows.h will hurt building of some thirdparty code or another anyway.

Consider using usual workarounds like including windows.h in front of OCCT headers or whatever issue you experience in your case.

Aaron Michalk's picture

The conflict was with Open Design Alliance DWG import/export libraries. Our workaround was to put an #ifndef AVOID_OCCT_WINDOWS_HEADER_DEFINES around the block so that the OCCT code compiles as before and our code compiles without the defines.

Dmitrii Pasukhin's picture

Thank you. I was used it, but for some reason didn't face that issue.

But I will look at the option with CMake. It is already working in case of PCH pretty well.

Best regards, Dmitrii.