Search code examples
c++visual-studio-2010dlltargetplatform

Find C++ platform target at compile time in visual studio


I am building my solution for x86 and x64 platforms. Does Visual Studio have any target platform variables so I find which platform I am building for in compile time?

For example:

HINSTANCE hinstLib; 
#ifdef TARGET_X86
hinstLib = LoadLibrary("32lib.dll"); 
#endif

#ifdef TARGET_X64
hinstLib = LoadLibrary("64lib.dll"); 
#endif

Solution

  • This is what I use:

    #if defined(_MSC_VER)
         // Microsoft VC compiler
    #    if defined(_WIN32)
    #        if defined(_WIN64)
                 // 64 bit windows
    #        else
                 // 32 bit windows
    #        endif
    #    endif
    #endif
    

    Note that _WIN32 is defined for 64 bit too.