Hi I need for my program to determine if it was compiled for 32 bit windows or 64 bit/any CPU. I need to choose a different COM server flag depending on the compilation options. Any ideas?
You want the CORFLAGS command-line app from Microsoft. http://msdn.microsoft.com/en-us/library/ms164699(VS.80).aspx
You could do this based on setting compile time constants and doing #ifs based on those to set a value that you can check to see which platform the application was compiled for. See http://stackoverflow.com/questions/524196/-net-target-platform-processor-at-compile-time.
The easiest other way is to check the IntPtr.Size property to see if it's 4 (32 bit), or 8 (64 bit).
You can use the IsWow64Process function to determine at runtime whethehr your COM server is a x64 or win32 process.
If you just want to know this during compile time: the compiler sets the _WIN64 macro.
Checking at run time if you are running a 64-bit application:
To see whether your process is 64-bit or 32-bit you can simply check the IntPtr.Size or any other pointer type. If you get 4 then you are running on 32-bit. If you get 8 then you are running on 64-bit.
What type of computer is your process running as:
You can check the ARCHITECTURE environment variable to see if you are running on an x64, ia64 or x86 machine.
Is your process running under emulation:
The Win32 API IsWow64Process will tell you if you are running a 32-bit application under x64. Wow64 means windows32 on windows64.
Contrary to what other people have posted: IsWow64Process will not tell you if you are running a 32-bit or a 64bit application. On 32-bit machines it will tell you FALSE for 32-bit applications when run, and on a 64-bit machine it will tell you TRUE for a 32-bit application. It only tells you if your application is running under emulation.
While it seems like an odd route to go, you can tell whether you're running in 32-bit (or 64-bit in WOW64) or 64-bit .NET code by checking IntPtr.Size.
On 32-bit/WOW64, IntPtr.Size is 4.
On 64-bit, IntPtr.Size is 8.
Source: Migrating 32-bit Managed Code to 64-bit Managed Code on MSDN.
use GetBinaryType api function and you will have the type of the file
this is the link to the api on msdn http://msdn.microsoft.com/en-us/library/aa364819(VS.85).aspx
the results are:
SCS_32BIT_BINARY = 32 bit exe
SCS_64BIT_BINARY = 64 bit exe
SCS_DOS_BINARY = DOS
SCS_OS216_BINARY = OS/2
SCS_WOW_BINARY = 16 bit
SCS_POSIX_BINARY = POSIX based
SCS_PIF_BINARY = PIF file that execute on DOS