cancel
Showing results for
Did you mean:

# A compiling error in a NXOpen C++ project when I include windows.h

Pioneer

Hi everyone,

I have a NXOpen C++ project, it can compile normally, however when I include <windows.h> in my project, some compilation error happens, it seems that the error is related to the UI.hpp. And I have no idea how to solve this problem.

2 REPLIES

# Re: A compiling error in a NXOpen C++ project when I include windows.h

Legend

You have to undefine CreateDialog (#undef CreateDialog).  The following is from the solution center.

```The problem where a program that contained "#include <NXOpen/UI.hxx>" would not compile can be avoided with the following work-around:
This is because windows.h is full of macros to cope with the Unicode vs multibyte Windows functions.  In the immediate problem CreateDialog is in fact a macro in windows.h that expands to CreateDialogW (assuming compiling for unicode).  This causes the declaration of the NX CreateDialog member function in UI.hxx to not parse correctly as it is interpreted as the macro due to being the same name - the standard dangers of the C macro processor.  There are several ways this can be made to work:
- Don't include windows.h before UI.hxx but after it. So in this case you can't have windows.h in stdafx.h.  Note this means you can't use the UI::CreateDialog as the call will get replaced with CreateDialogW
- #undef CreateDialog after the #include of "stdafx.h" and before UI.hxx - this means you can't call the windows function via CreateDialog but you can explicitly call CreateDialogW (or CreateDialogA) and that will work so is probably the simplest way to proceed
- Keep files that use windows calls and NXopen calls separate
Note that GetMessage is a similar problem symbol (windows.h vs NXException)
Note also that having a "using namespace std;" before NXOpen headers isn't recommended as this may affect the parsing of the headers too once the using is in effect - using directives should in general be after all includes in the source files - this is general recommended C++ style.```

# Re: A compiling error in a NXOpen C++ project when I include windows.h

Pioneer

Thank you very much for your solution!