首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > windows >

怎么通过代码识别当前机器操作系统的位数是32还是64

2012-02-03 
如何通过代码识别当前机器操作系统的位数是32还是64项目中需要甄别安装软件的机器的操作系统的位数,从而选

如何通过代码识别当前机器操作系统的位数是32还是64
项目中需要甄别安装软件的机器的操作系统的位数,从而选择不同类型的驱动进行安装!请各位老师给予答案,感谢,感谢,万分感谢!

[解决办法]

C/C++ code
利用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 } 

热点排行