Posted By

shadevampire on 07/27/11


Tagged

check windows checking bit bits 32 64 bitness


Versions (?)

Reliably Checking Windows Bitness (32-bit or 64-bit) With C++


 / Published in: C++
 

URL: http://mark.koli.ch/2009/10/reliably-checking-os-bitness-32-or-64-bit-on-windows-with-a-tiny-c-app.html

See on the source (url)

  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include "comutil.h"
  4.  
  5. #define RESPONSE_32_BIT "32"
  6. #define RESPONSE_64_BIT "64"
  7.  
  8. using namespace std;
  9.  
  10. typedef BOOL (WINAPI *IW64PFP)(HANDLE, BOOL *);
  11.  
  12. int main(int argc, char **argv){
  13.  
  14. BOOL res = FALSE;
  15.  
  16. // When this application is compiled as a 32-bit app,
  17. // and run on a native 64-bit system, Windows will run
  18. // this application under WOW64. WOW64 is the Windows-
  19. // on-Windows subsystem that lets native 32-bit applications
  20. // run in 64-bit land. This calls the kernel32.dll
  21. // API to see if this process is running under WOW64.
  22. // If it is running under WOW64, then that clearly means
  23. // this 32-bit application is running on a 64-bit OS,
  24. // and IsWow64Process will return true.
  25. IW64PFP IW64P = (IW64PFP)GetProcAddress(
  26. GetModuleHandle(L"kernel32"), "IsWow64Process");
  27.  
  28. if(IW64P != NULL){
  29. IW64P(GetCurrentProcess(), &res);
  30. }
  31.  
  32. cout << ((res) ? RESPONSE_64_BIT : RESPONSE_32_BIT) << endl;
  33.  
  34. return 0;
  35.  
  36. }

Report this snippet  

You need to login to post a comment.