정리

[Win32 API] 64bit OS인지 확인하려면 IsWow64Process

저장소/VC++
64bit OS의 확인은 IsWow64Process API를 사용하면 된다.
(중요한 것은 Client는 XP SP2 이상부터, Server는 2003 SP1 부터 지원된다는 것이다.
사용 전 주의가 필요하다.)

API 원형은 다음과 같다.

BOOL WINAPI IsWow64Process(
__in HANDLE hProcess,
__out PBOOL Wow64Process );

Parameters

hProcess

A handle to the process.

Wow64Process

A pointer to a value that is set to TRUE if the process is running under WOW64. Otherwise, the value is set to FALSE.

Return Value

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

If the application is a 64-bit application running under 64-bit Windows, the Wow64Process parameter is set to FALSE.

To compile an application that uses this function, define _WIN32_WINNT as 0x0501 or later. For more information, see Using the SDK Headers.


샘플 코드는 다음과 같다.
MSDN 발췌
#include <windows.h>
#include <stdio.h>

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

LPFN_ISWOW64PROCESS fnIsWow64Process;

BOOL IsWow64()
{
    BOOL bIsWow64 = FALSE;

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

void main()
{
    if(IsWow64())
        printf("Running on WOW64\n");
    else printf("Running on 32-bit Windows\n");
}