今天review同事的代码,碰巧看到这一段,自己对这些也不熟悉。碰巧遇到就查阅资料记录下来。
wow64模式,MSDN的解释如下:
WOW64 is the x86 emulator that allows 32-bit Windows-based applications to run seamlessly on 64-bit Windows.
简单说来,就是64位的系统提供一个模拟环境,使得32位程序也能无差别(与运行在32位系统上)。BOOL IsWow64Process(HANDLE hProcess)
{
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fn_IsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(_T("kernel32.dll", "IsWow64Process"));
BOOL bIsWow64 = FALSE;
if (NULL != fn_IsWow64Process) {
if (!fn_IsWow64Process(hProcess, &bIsWow64)) {
//maybe some error
}
}
return bIsWow64;
}
基本思路如上述,没有验证,使用时请小心错误。
值得注意的是MSDN提到:
If the application is a 64-bit application running under 64-bit Windows, theWow64Process parameter is set to FALSE.
To compile an application that uses this function, define _WIN32_WINNT as 0x0501 or later.
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");
}
Note that this technique is not a reliable way to detect whether the operating system is a 64-bit version of Windows because the Kernel32.dll in current versions of 32-bit Windows also contains this function.
这个方法不能判断操作系统是否是64位的,因为32位版本的windows系统也有这个函数,哈哈!坑多,要小心!
2015-02-28 17:31