How to determine if an executable program for 64 bits has been compiled?

I need my program to determine if it was compiled for 32-bit windows or 64-bit / any processor. I need to select a different COM server flag depending on the compilation options. Any ideas?

+6
c # 64bit
source share
9 answers

Runtime check if you are using a 64-bit application:

To find out if your process is 64-bit or 32-bit, you can simply check IntPtr.Size or any other type of pointer. If you get 4, then you are working on 32-bit. If you get 8, you are working on a 64-bit basis.

What type of your computer works like:

You can check the PROCESSOR_ARCHITECTURE environment variable to make sure that you are running on an x64, ia64 or x86 machine.

Does your process work under emulation:

The Win32 API IsWow64Process will tell you if you are using a 32-bit application under x64. Wow64 means Windows32 on windows64.

Unlike other posted posts: IsWow64Process will not tell you if you are using a 32-bit or 64-bit application. On 32-bit machines, it will tell you FALSE for 32-bit applications at startup, and on a 64-bit machine, it will tell you TRUE for a 32-bit application. It only reports if your application is running under emulation.

+7
source share

Do you know Environment.Is64BitProcess ? It determines whether the current current process is a 64-bit process.

+3
source share

You need the CORFLAGS command-line application from Microsoft. http://msdn.microsoft.com/en-us/library/ms164699(VS.80).aspx

+2
source share

You can use the IsWow64Process function to determine at runtime if your COM server is an x64 or win32 process.

If you just want to know this at compile time: the compiler installs the _WIN64 macro.

+2
source share

use the getBinaryType api function and you will have a file type

this is a link to the api on msdn http://msdn.microsoft.com/en-us/library/aa364819(VS.85).aspx

results:

SCS_32BIT_BINARY = 32 bits exe

SCS_64BIT_BINARY = 64 bit exe

SCS_DOS_BINARY = DOS

SCS_OS216_BINARY = OS / 2

SCS_WOW_BINARY = 16 bits

SCS_POSIX_BINARY = POSIX-based

SCS_PIF_BINARY = PIF file that runs on DOS

+2
source share

You can do this by setting compile time constants and executing #ifs based on these parameters to set a value that you can check to see which platform the application was compiled on. See Target platform / processor at compile time .

The easiest way is to check the IntPtr.Size property to see if it is 4 (32 bits) or 8 (64 bits).

+1
source share
+1
source share

While it seems like a weird route, you can find out if you work in 32-bit (or 64-bit in WOW64) or 64-bit .NET code by checking IntPtr.Size.

In 32-bit / WOW64, IntPtr.Size is set to 4.

In 64-bit format, IntPtr.Size is set to 8.

Source: Porting 32-bit managed code to 64-bit managed code on MSDN.

+1
source share

You can use predefined macros to check the type of compilation.

  #if (_WIN64) const bool IS_64 = true; #else const bool IS_64 = false; #endif 
0
source share

All Articles