VOID ShowProcessors()
{
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pBuffer = NULL;
DWORD dwSize = 0;
DWORD dwProcCoreCount = 0;
BOOL bResult = GetLogicalProcessorInformation( pBuffer , &dwSize );
if ( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
{
OutputDebugString(TEXT("不能获取处理器信息"));
return;
}
pBuffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(dwSize);
bResult = GetLogicalProcessorInformation( pBuffer , &dwSize );
if ( !bResult )
{
free(pBuffer);
OutputDebugString(TEXT("不能获取处理器信息"));
return;
}
DWORD lpiCount = dwSize / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
for ( DWORD current = 0 ; current < lpiCount ; ++current )
{
if ( pBuffer[current].Relationship == RelationProcessorCore )
{
if ( pBuffer[current].ProcessorCore.Flags == 1 )
{
OutputDebugString(TEXT(" + one CPU core (HyperThreading)\n"));
}
else
{
OutputDebugString(TEXT(" + one CPU socket\n"));
}
++dwProcCoreCount;
}
}
TCHAR pStr[MAX_PATH];
StringCchPrintf( pStr , MAX_PATH , TEXT(" -> %d active CPU(s)\n") , dwProcCoreCount );
OutputDebugString( pStr );
free(pBuffer);
}