mirror of
https://github.com/janbodnar/Windows-API-examples.git
synced 2024-11-11 06:29:58 +00:00
39 lines
800 B
C
39 lines
800 B
C
#include <windows.h>
|
|
#include <wchar.h>
|
|
|
|
int wmain(void) {
|
|
|
|
DWORD BufSize = MAX_PATH;
|
|
DWORD mhz = MAX_PATH;
|
|
HKEY key;
|
|
|
|
long r = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &key);
|
|
|
|
if (r != ERROR_SUCCESS) {
|
|
|
|
wprintf(L"RegOpenKeyExW() failed %ld", GetLastError());
|
|
return 1;
|
|
}
|
|
|
|
r = RegQueryValueExW(key, L"~MHz", NULL, NULL, (LPBYTE) &mhz, &BufSize);
|
|
|
|
if (r != ERROR_SUCCESS) {
|
|
|
|
wprintf(L"RegQueryValueExW() failed %ld", GetLastError());
|
|
return 1;
|
|
}
|
|
|
|
wprintf(L"CPU speed: %lu MHz\n", mhz);
|
|
|
|
r = RegCloseKey(key);
|
|
|
|
if (r != ERROR_SUCCESS) {
|
|
|
|
wprintf(L"Failed to close registry handle %ld", GetLastError());
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|