windows C++ 判断系统位数64还是32位

int getSystemBits()
{
	SYSTEM_INFO si;

	typedef VOID(WINAPI *LPFN_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
	HMODULE hModule = GetModuleHandle("kernel32");
	if (hModule == NULL)
	{
		cout << "load module kernel32 failed";
		return -1;
	}
	LPFN_GetNativeSystemInfo fnGetNativeSystemInfo = (LPFN_GetNativeSystemInfo)GetProcAddress(hModule, "GetNativeSystemInfo");;
	if (NULL != fnGetNativeSystemInfo)
	{
		fnGetNativeSystemInfo(&si);
	}
	else
	{
		GetSystemInfo(&si);
	}


	if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
		si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
	{
		cout << "system bit is 64bits"<<endl;
		return 64;
	}
	cout << "system bit is 32bits" << endl;
	return 32;
}

你可能感兴趣的:(windows,c++,开发语言)