Home
Archives

How to tell if your application is running on a 64-bit OS in C++

There are really two different things that need to be checked to see if your app is running on a 64-bit OS.  The first thing you can do if you are a 32-bit application is to see if your app is running under the 32-bit emulation.  This is called running under the WOW (windows on windows, I think...).

From MSFT:

#include <windows.h>

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

LPFN_ISWOW64PROCESS 
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle("kernel32"),"IsWow64Process");

BOOL IsWow64()
{
    BOOL bIsWow64 = FALSE;
 
    if (NULL != fnIsWow64Process)
    {
        if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
        {
            // handle error
        }
    }
    return bIsWow64;
}

The next thing you could check for is the processor architecture.  GetSystemInfo allows you to check the local machine's processor type.

SYSTEM_INFO sysInformation;

GetSystemInfo(&sysInformation);
WORD cpu = sinfo.wProcessorArchitecture;

if (cpu == PROCESSOR_ARCHITECTURE_IA64 || cpu == PROCESSOR_ARCHITECTURE_AMD64)
{
     //you are on a 64-bit CPu
}
  


There you have it...best to check both items in case you use your code in both 64-bit and 32-bit apps.