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

Answers


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.


Have a look here: http://msdn.microsoft.com/en-US/library/b0084kay.aspx

_WIN64 or _M_X64 should work.

So for your example:

HINSTANCE hinstLib; 
#ifdef _WIN64
    hinstLib = LoadLibrary("64lib.dll"); 
#else
    hinstLib = LoadLibrary("32lib.dll"); 
#endif

Need Your Help

Loading Values into auto generated HTML input elements using javascript

javascript html

I am using a javascript function to populate html element generated automatically after submitting a form from a different div.