Categories: Visual StudioWindows

How to check Windows or process is 64bit

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
bool Is64BitWindows()
{
#if defined(_WIN64)
 return true;  // 64-bit programs run only on Win64
#elif defined(_WIN32)

 // 32-bit programs run on both 32-bit and 64-bit Windows
 // so must sniff
 BOOL f64 = FALSE;
 LPFN_ISWOW64PROCESS fnIsWow64Process;

 fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
 if (NULL != fnIsWow64Process)
 {
  return !!(fnIsWow64Process(GetCurrentProcess(), &f64) && f64);
 }

 return false;
#else
 return false; // Win64 does not support Win16
#endif
}

http://stackoverflow.com/questions/336633/how-to-detect-windows-64-bit-platform-with-net

Other functions, for finding CPU and whether the process is 64bit.

typedef void(WINAPI *LPFN_GetNativeSystemInfo)(LPSYSTEM_INFO);
LPCWSTR GetPlatformW()
{
 static WCHAR sT[64];
 static bool done = false;
 if (done)
  return sT;

 LPFN_GetNativeSystemInfo fnGetNativeSystemInfo = (LPFN_GetNativeSystemInfo)GetProcAddress(
  GetModuleHandle(TEXT("kernel32")), "GetNativeSystemInfo");

 if (NULL == fnGetNativeSystemInfo)
 {
  lstrcpy(sT, L"Unknown");
 }
 else
 {
  SYSTEM_INFO si = { 0 };
  fnGetNativeSystemInfo(&si);
  switch (si.wProcessorArchitecture)
  {
  case PROCESSOR_ARCHITECTURE_AMD64: lstrcpy(sT, L"AMD64"); break;
  case PROCESSOR_ARCHITECTURE_ARM: lstrcpy(sT, L"ARM"); break;
  case PROCESSOR_ARCHITECTURE_IA64: lstrcpy(sT, L"IA64"); break;
  case PROCESSOR_ARCHITECTURE_INTEL: lstrcpy(sT, L"INTEL"); break;
  default:lstrcpy(sT, L"Unknown"); break;
  }
 }
 return sT;
}

bool Is64BitProcess()
{
#if defined(_WIN64)
 return true;
#else
 return false;
#endif
}

I tried to run this code only on AMD64. I don’t know what happens in ARM or IA64 platforms.

admin

Recent Posts

Obtain global IP in bash

In current Internet environment, every PC is assigned a private IP. If global IP is…

3 years ago

Create log file in the directory of the script in Python

__file__ is the script file itself. From python3.9 above, it is an absolute path, otherwise…

3 years ago

RichTextBox’s font changes automatically in C#

You need to clear these two flags IMF_DUALFONT and IMF_AUTOFONT to keep font unchanged.

3 years ago

Test post to check image URL

This is an image inserted by wordpress 'Add Media'

3 years ago

msbuild says ‘target does not exist’

I don't know what is going wrong but... How to fix it Open the solution…

3 years ago

Creating a break point that hits on calling win32 api

Create a break point that hits when CreateProcess was called Enter a Function Breakpoint Enter…

4 years ago