Windows API一日一練(74)GetSystemInfo函數
有一次,我正在開發一個視頻壓縮程式,而壓縮演算法是需要非常高效的,也就是需要使用到CPU的多媒體指令。在X86的領域裡,目前主要有兩家CPU,就是INTEL和AMD。它們的多媒體指令是不一樣的。為了區分這種不同的指令,就需要調用函數GetSystemInfo來擷取CPU的資訊,然後再調用不同的動態串連庫來進行多媒體資料壓縮。
函數GetSystemInfo聲明如下:
WINBASEAPI
VOID
WINAPI
GetSystemInfo(
__out LPSYSTEM_INFO lpSystemInfo
);
lpSystemInfo是返回硬體資訊的結構。
調用函數的例子如下:
#001 //
#002 //擷取當前系統的硬體資訊。
#003 //蔡軍生 2007/11/15 QQ:9073204 深圳
#004 void GetHardInfo(void)
#005 {
#006 //
#007 SYSTEM_INFO sysInfo;
#008
#009 //擷取系統的資訊。
#010 ::GetSystemInfo(&sysInfo);
#011
#012 //顯示當前系統的資訊。
#013 //
#014 const int nBufSize = 512;
#015 TCHAR chBuf[nBufSize];
#016 ZeroMemory(chBuf,nBufSize);
#017
#018 wsprintf(chBuf,_T("OEM ID: %u/n"),sysInfo.dwOemId);
#019 OutputDebugString(chBuf);
#020
#021 wsprintf(chBuf,_T("CPU個數: %u/n"),sysInfo.dwNumberOfProcessors);
#022 OutputDebugString(chBuf);
#023
#024 wsprintf(chBuf,_T("記憶體分頁大小: %u/n"),sysInfo.dwPageSize);
#025 OutputDebugString(chBuf);
#026
#027 wsprintf(chBuf,_T("CPU類型: %u/n"),sysInfo.dwProcessorType);
#028 OutputDebugString(chBuf);
#029
#030 wsprintf(chBuf,_T("CPU架構: %u/n"),sysInfo.wProcessorArchitecture);
#031 OutputDebugString(chBuf);
#032
#033 wsprintf(chBuf,_T("CPU的層級: %u/n"),sysInfo.wProcessorLevel);
#034 OutputDebugString(chBuf);
#035
#036 wsprintf(chBuf,_T("CPU的版本: %u/n"),sysInfo.wProcessorRevision);
#037 OutputDebugString(chBuf);
#038
#039 }