Created
July 18, 2025 12:08
-
-
Save Aetopia/81f6b8893c5c03c93fdcd344c9802af6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <string> | |
| #include <vector> | |
| #include <format> | |
| #include <initguid.h> | |
| #include <windows.h> | |
| #include <setupapi.h> | |
| #include <devguid.h> | |
| #include <devpkey.h> | |
| std::wstring GetCpuName() | |
| { | |
| HDEVINFO info = SetupDiGetClassDevsW(&GUID_DEVCLASS_PROCESSOR, NULL, NULL, DIGCF_PRESENT); | |
| SP_DEVINFO_DATA data = {.cbSize = sizeof(SP_DEVINFO_DATA)}; | |
| int index{}; | |
| std::vector<byte> string{}; | |
| for (; SetupDiEnumDeviceInfo(info, index, &data); index++) | |
| if (string.empty()) | |
| { | |
| DWORD size{}; | |
| DEVPROPTYPE type{}; | |
| SetupDiGetDevicePropertyW(info, &data, &DEVPKEY_Device_FriendlyName, &type, NULL, 0, &size, 0); | |
| string.resize(size); | |
| SetupDiGetDevicePropertyW(info, &data, &DEVPKEY_Device_FriendlyName, &type, string.data(), size, NULL, 0); | |
| } | |
| SetupDiDestroyDeviceInfoList(info); | |
| return std::format(L"{}x {}", index, std::wstring(reinterpret_cast<PWSTR>(string.data()))); | |
| } | |
| int main() | |
| { | |
| __builtin_printf("%ls\n", GetCpuName().c_str()); | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment