Q:

Correct way to check if Windows is 64 bit or not, on runtime? (C++)

bool Win64bit = (sizeof(int*) == 8) ? 1 : 0;

I need this so my app can use Windows registry functions properly (or do i need?).
So am i doing it right ?

A:

Here's what Raymond Chen suggests in his blog at http://blogs.msdn.com/oldnewthing/archive/2005/02/01/364563.aspx:
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;
    return IsWow64Process(GetCurrentProcess(), &f64) && f64;
#else
    return FALSE; // Win64 does not support Win16
#endif
}

A:

No, this cannot work as a run-time check, since sizeof(int*) is fixed at compile time at the point where you choose to compile your program as either 32-bit or 64-bit, and once compiled, the check will have the same fixed result regardless of which platform you are running it on.
However, since a 64-bit program cannot run on a 32-bit platform, you will find that your check works correctly without modification as a compile-time check:
If you compile your program as 64-bit, your program will use the 64-bit API because of your code above, and will work correctly on a 64-bit version of windows.  It will fail to run on 32-bit windows at all, so there will be no chance you accidentally use the 64-bit API on a 32-bit version of windows.
v++ platform == 64-bit => sizeof(int*) == 8 => use 64-bit API
AND
( windows platform == 64-bit => 64-bit API works
  OR
  windows platform == 32-bit => program does not run )

If you compile your program in 32-bit mode, your program will correctly use the 32-bit APIs, which will work on a 64-bit windows platform in 32-bit compatibility mode, and will obviously work on a 32-bit platform.
v++ platform == 32-bit => sizeof(int*) == 4 => use 32-bit API
AND
( windows platform == 64-bit => 32-bit API works using compatibility mode
  OR
  windows platform == 32-bit => 32-bit API works )

If you really want to access 64-bit APIs from a 32-bit program I daresay there are APIs to do it, but I'm not sure that you would want to.

A:

In addition, one can use IsWow64Process to check whether you're a 32Bit process (sizeof(void*)==4) running under the WoW64 emulation on a 64bit Windows machine.

