Determine OS bit using sizeof(void*) ???

Hi all,
I found out a way to find the bit of OS that is whether x86 or x64. Is this a reliable method:
1
2
3
4
5
6
7
8
9
10
11
12
13

if(sizeof(void*)==4)
{
//32 bit!
//do 32 bit stuff...
}else if(sizeof(void*)==8)
{
//64 bit! 
//do 64 bit stuff...
}else{
//Not supported!
/*You dont use neither 32 bit nor 64 bit*/
}

Please help...
Last edited on
Yes, it works, but the check is done at compile time, not at runtime. You should already know for what platform are you compiling, don't you ?
I need to do it at runtime.
How can I do this accurately...?
You can use a function like this to detect if you are running under WOW64 (which means you already know that your application is compiled as X86):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <windows.h>

bool IsWow64()
{
  BOOL bIsWow64 = FALSE;

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

  LPFN_ISWOW64PROCESS fnIsWow64Process;

  HMODULE module = GetModuleHandle(_T("kernel32"));
  const char funcName[] = "IsWow64Process";
  fnIsWow64Process = (LPFN_ISWOW64PROCESS)
    GetProcAddress(module, funcName);

  if(NULL != fnIsWow64Process)
  {
    if (!fnIsWow64Process(GetCurrentProcess(),
                          &bIsWow64))
      throw std::exception("Unknown error");
  }
  return bIsWow64 != FALSE;
}

int main()
{
  if (IsWow64())
    printf("The process is running under WOW64.\n");
  else
    printf("The process is not running under WOW64.\n");

  printf("\nPress Enter to continue...");
  getchar();
  return 0;
}
Splendid!
Now in order to get more info of the processor, I can use GetSystemInfo(...) or GetNativeSystemInfo(...) !
closed account (13bSLyTq)
Can you please just go to skidforums.com please, you are asking us for entire code for your easy project.
closed account (N36fSL3A)
you are asking us for entire code for your easy project.
That's kind of rude. The tone of that reply was completely unnecessary.

The fact that you called his project easy is even more rude, which isn't like you. Please don't do that again.
Topic archived. No new replies allowed.