1、IsWow64Process
确定指定进程是否运行在64位操作系统的32环境(Wow64)下。
语法
BOOL WINAPI IsWow64Process(
__in HANDLE hProcess,
__out PBOOL Wow64Process
);
参数
hProcess
进程句柄。该句柄必须具有PROCESS_QUERY_INFORMATION 或者 PROCESS_QUERY_LIMITED_INFORMATION 访问权限
Wow64Process
指向一个bool值,
如果该进程是32位进程,运行在64操作系统下,该值为true,否则为false。
如果该进程是一个64位应用程序,运行在64位系统上,该值也被设置为false。
返回值
如果函数成功返回值为非零值。
如果该函数失败,则返回值为零。要获取扩展的错误的信息,请调用GetLastError .
微软的例子:
#include
#include
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL IsWow64()
{
BOOL bIsWow64 = FALSE;
//IsWow64Process is not available on all supported versions of Windows.
//Use GetModuleHandle to get a handle to the DLL that contains the function
//and GetProcAddress to get a pointer to the function if available.
fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
if(NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
{
//handle error
}
}
return bIsWow64;
}
int main( void )
{
if(IsWow64())
_tprintf(TEXT("The process is running under WOW64.\n"));
else
_tprintf(TEXT("The process is not running under WOW64.\n"));
return 0;
}
注意:使用此函数判断操作系统是32位还是64位并不合适,勉强要用的话,可以指向一个32位进程。
2、比较合适的做法是:
BOOL Is64bitSystem()
{
SYSTEM_INFO si;
GetNativeSystemInfo(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
return TRUE;
else
return FALSE;
}
补充知识:C编程注意32位机器和64位机器的差别及unsigned