Windows API一日一練(74)GetSystemInfo函數

來源:互聯網
上載者:User
  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  }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.