Where is WIN32 defined, and how can I include this definition in my project?

后端 未结 6 1002
逝去的感伤
逝去的感伤 2021-01-11 21:06

I am including a third party header and source file into my project.

At the top of the header there is this:

#if defined(WIN32) || defined(WIN16)
#i         


        
相关标签:
6条回答
  • 2021-01-11 21:10

    For those seeking answers to the

    where is WIN32 defined

    part of the questions, I've found it defined in:

    minwindef.h

    ole2.h

    Note, I have no confidence that these are the only places it's defined. I expect there are probably other files where it's defined. Nevertheless, I thought this might help some people.

    0 讨论(0)
  • 2021-01-11 21:10

    Some WIN32 defined in the compiler . Just like this,If you use the gcc for windows , WIN32 is defined . If you use the gcc for linux , WIN32 is not defined :)
    So , the macros is a switch. You can define it to use somethine , and not define it to unuse something.

    0 讨论(0)
  • 2021-01-11 21:13

    Check your includes. I am guessing that the third party header is included prior to the windows.h. So, in your main.cpp or equal it should be

    #include <windows.h> // this will also include windefs.h
    #include <thirdParty.h>
    

    and not the other way around.

    Hope that helps.

    0 讨论(0)
  • 2021-01-11 21:18

    Depends on your project setup. WIN32 is defined inside the windows header files, but you can pass it to the compiler as well ("-DWIN32" for gcc for example). Try it and see whether it compiles.

    0 讨论(0)
  • 2021-01-11 21:21

    Visual Studio has the built-in define _WIN32. mingw-gcc has WIN32 and _WIN32 built-in so the project was likely tested using gcc. You might add

    
    #if defined(_WIN32) && !defined(WIN32)
    #define WIN32
    #endif
    

    or just add a -DWIN32 to the CFLAGS.

    0 讨论(0)
  • 2021-01-11 21:26

    You can simply include the windows header files (windows.h) before including the third party header - as you already found out WIN32 is defined there but technicaly it could be defined anywhere (so if the third party project is not including the windows headers check if it's being defined in the compiler project settins directly).

    BTW there is also a _WIN32 define that is set by the compiler, it's possibly a better idea to look for this define if checking if the code is being compiled under windows;

    0 讨论(0)
提交回复
热议问题