最近因为要根据系统的情况来决定安装那种驱动,所以需要判断下系统是32bit,还是64bit
方法一:主要是利用getSystemWow64Directory这个函数来判断!
typedef UINT (WINAPI* GETSYSTEMWOW64DIRECTORY)(LPTSTR, UINT);
BOOL IsWow64(void)
{
#ifdef _WIN64
return FALSE;
#else
GETSYSTEMWOW64DIRECTORY getSystemWow64Directory;
HMODULE hKernel32;
TCHAR Wow64Directory[MAX_PATH];
hKernel32 = GetModuleHandle(TEXT("kernel32.dll"));
if (hKernel32 == NULL) {
//
// This shouldn't happen, but if we can't get
// kernel32's module handle then assume we are
//on x86. We won't ever install 32-bit drivers
// on 64-bit machines, we just want to catch it
// up front to give users a better error message.
//
return FALSE;
}
getSystemWow64Directory = (GETSYSTEMWOW64DIRECTORY)
GetProcAddress(hKernel32, "GetSystemWow64DirectoryW");
if (getSystemWow64Directory == NULL) {
//
// This most likely means we are running
// on Windows 2000, which didn't have this API
// and didn't have a 64-bit counterpart.
//
return FALSE;
}
if ((getSystemWow64Directory(Wow64Directory,
sizeof(Wow64Directory)/sizeof(TCHAR)) == 0) &&
(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
return FALSE;
}
//
// GetSystemWow64Directory succeeded
// so we are on a 64-bit OS.
//
return TRUE;
#endif
}
方法二:主要是利用IsWow64Process
#include <windows.h> typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress( GetModuleHandle("kernel32"),"IsWow64Process"); BOOL IsWow64() { BOOL bIsWow64 = FALSE; if (NULL != fnIsWow64Process) { if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64)) { // handle error } } return bIsWow64; }转载于:https://blog.51cto.com/renjwjx/172721