处理器信息
使用void WINAPI GetSystemInfo(..) (MSDN)
这将返回一个 SYSTEM_INFO 结构,其中包含:
typedef struct _SYSTEM_INFO {
union {
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO;
枚举设备
使用IPortableDeviceManager 接口枚举设备。 MSDN 详细描述了这个 API。
这是该页面的代码 sn-p:
// Create PortableDeviceManager
HRESULT hr = CoCreateInstance(CLSID_PortableDeviceManager,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pPortableDeviceManager));
if (FAILED(hr))
{
printf("! Failed to CoCreateInstance CLSID_PortableDeviceManager, hr = 0x%lx\n",hr);
return;
}
// Get number of devices
if (SUCCEEDED(hr))
{
hr = pPortableDeviceManager->GetDevices(NULL, &cPnPDeviceIDs);
if (FAILED(hr))
{
printf("! Failed to get number of devices on the system, hr = 0x%lx\n",hr);
}
}
// Report the number of devices found. NOTE: we will report 0, if an error
// occured.
printf("\n%d Windows Portable Device(s) found on the system\n\n", cPnPDeviceIDs);
// Enumerate the device information
if (SUCCEEDED(hr) && (cPnPDeviceIDs > 0))
{
pPnpDeviceIDs = new (std::nothrow) PWSTR[cPnPDeviceIDs];
if (pPnpDeviceIDs != NULL)
{
DWORD dwIndex = 0;
hr = pPortableDeviceManager->GetDevices(pPnpDeviceIDs, &cPnPDeviceIDs);
if (SUCCEEDED(hr))
{
// For each device found, display the devices friendly name,
// manufacturer, and description strings.
for (dwIndex = 0; dwIndex < cPnPDeviceIDs; dwIndex++)
{
printf("[%d] ", dwIndex);
DisplayFriendlyName(pPortableDeviceManager, pPnpDeviceIDs[dwIndex]);
printf(" ");
DisplayManufacturer(pPortableDeviceManager, pPnpDeviceIDs[dwIndex]);
printf(" ");
DisplayDescription(pPortableDeviceManager, pPnpDeviceIDs[dwIndex]);
}
}
else
{
printf("! Failed to get the device list from the system, hr = 0x%lx\n",hr);
}
}
}
// Free memory used to store the information
for (dwIndex = 0; dwIndex < cPnPDeviceIDs; dwIndex++)
{
CoTaskMemFree(pPnpDeviceIDs[dwIndex]);
pPnpDeviceIDs[dwIndex] = NULL;
}
// Delete the array of PWSTR pointers
delete [] pPnpDeviceIDs;
pPnpDeviceIDs = NULL;