ソースコード
#include "stdafx.h"
struct ProcessorInfo
{
unsigned int processors;
unsigned int architecture;
unsigned int type;
unsigned int level;
unsigned int revision;
bool operator()(void);
};
/* XP以降に対応 */
bool ProcessorInfo::operator()(void)
{
this->architecture = 0;
this->level = 0;
this->processors = 0;
this->revision = 0;
this->type = 0;
HMODULE dll = ::LoadLibrary(_T("kernel32.dll"));
if (dll==NULL)
{
return false;
}
typedef void (CALLBACK* GetNativeSystemInfoAPI)(LPSYSTEM_INFO);
GetNativeSystemInfoAPI api = (GetNativeSystemInfoAPI)::GetProcAddress(dll,"GetNativeSystemInfo");
if (api==NULL)
{
::FreeLibrary(dll);
return false;
}
SYSTEM_INFO inf={0};
api(&inf);
::FreeLibrary(dll);
this->architecture = inf.wProcessorArchitecture;
this->level = inf.wProcessorLevel;
this->processors = inf.dwNumberOfProcessors;
this->revision = inf.wProcessorRevision;
this->type = inf.dwProcessorType;
return true;
}
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
ProcessorInfo pinf;
if (pinf())
{
wchar_t buffer[1000];
swprintf_s(buffer, 1000, L"%d Core, Type:%d",
pinf.processors,
pinf.type);
::MessageBox(NULL, buffer, _T(""), MB_OK);
}
else
{
::MessageBox(NULL, _T("取得に失敗しました"), _T(""), MB_OK);
}
return 0;
}