c++ GetSystemInfo
时间: 2023-07-05 22:36:13 浏览: 55
`GetSystemInfo`函数是Windows API中的一个函数,用于获取系统的基本信息,包括处理器架构(x86或x64)、处理器数量、页面大小等。
`GetSystemInfo`函数的定义如下:
```cpp
VOID WINAPI GetSystemInfo(
LPSYSTEM_INFO lpSystemInfo
);
```
参数`lpSystemInfo`是一个指向SYSTEM_INFO结构体的指针,调用该函数后,系统信息会被写入该结构体中。
下面是一个示例程序,演示如何使用`GetSystemInfo`函数获取系统信息:
```cpp
#include <iostream>
#include <windows.h>
int main()
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
std::cout << "Processor Architecture: ";
switch (sysInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
std::cout << "x64" << std::endl;
break;
case PROCESSOR_ARCHITECTURE_INTEL:
std::cout << "x86" << std::endl;
break;
default:
std::cout << "Unknown" << std::endl;
break;
}
std::cout << "Number of Processors: " << sysInfo.dwNumberOfProcessors << std::endl;
std::cout << "Page Size: " << sysInfo.dwPageSize << " bytes" << std::endl;
return 0;
}
```
在上述示例中,我们首先定义了一个SYSTEM_INFO结构体变量`sysInfo`,然后调用`GetSystemInfo`函数将系统信息写入该结构体中。最后,我们输出了一些系统信息,包括处理器架构、处理器数量、页面大小等。
需要注意的是,使用`GetSystemInfo`函数需要包含Windows.h头文件。