Reputation: 12004
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?
Upvotes: 8
Views: 13108
Reputation: 22283
Are you aware of Environment.Is64BitProcess
?
It determines whether the current running process is a 64-bit process.
Upvotes: 3
Reputation: 347216
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 PROCESSOR_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.
Upvotes: 7
Reputation: 49251
You can use the Predefined Macros to check compilation type
#if (_WIN64)
const bool IS_64 = true;
#else
const bool IS_64 = false;
#endif
Upvotes: 0
Reputation: 21
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
Upvotes: 2
Reputation: 88796
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.
Upvotes: 1
Reputation: 10239
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 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).
Upvotes: 1
Reputation: 43575
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.
Upvotes: 2
Reputation: 4546
You want the CORFLAGS command-line app from Microsoft. http://msdn.microsoft.com/en-us/library/ms164699(VS.80).aspx
Upvotes: 2