Created
July 5, 2024 11:53
-
-
Save DJm00n/038bd2ba5ae067d6228da3dc6dcf7489 to your computer and use it in GitHub Desktop.
SetupApi GetDeviceInstanceId GetDeviceName
This file contains 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
static void GetDeviceInstanceId(const char* device_interface, char* instance_id, size_t len) | |
{ | |
HDEVINFO devinfo; | |
SP_DEVICE_INTERFACE_DATA interface_data; | |
SP_DEVINFO_DATA device_data; | |
name[0] = '\0'; | |
devinfo = SetupDiCreateDeviceInfoList(NULL, NULL); | |
SDL_zero(interface_data); | |
interface_data.cbSize = sizeof(interface_data); | |
SetupDiOpenDeviceInterface(&devinfo, device_interface, 0, interface_data); | |
SDL_zero(device_data); | |
device_data.cbSize = sizeof(device_data); | |
SetupDiGetDeviceInterfaceDetail(devinfo, interface_data, NULL, 0, NULL, device_data); | |
SetupDiGetDeviceProperty(devinfo, device_data, DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING, instance_id, len); | |
//SetupDiGetDeviceInstanceId(devinfo, device_data, instance_id, len); | |
SetupDiDeleteDeviceInterfaceData(devinfo, interface_data); | |
SetupDiDestroyDeviceInfoList(devinfo); | |
} | |
static void GetDeviceName(const char *instance_id, char *name, size_t len) | |
{ | |
HDEVINFO devinfo; | |
SP_DEVINFO_DATA device_data; | |
name[0] = '\0'; | |
SDL_zero(device_data); | |
device_data.cbSize = sizeof(device_data); | |
SetupDiOpenDeviceInfo(devinfo, instance_id, NULL, 0, device_data); | |
SetupDiGetDeviceProperty(devinfo, &device_data, DEVPKEY_NAME, DEVPROP_TYPE_STRING, name, len, 0); | |
//SetupDiGetDeviceRegistryPropertyA(devinfo, &data, SPDRP_DEVICEDESC, NULL, (PBYTE)name, (DWORD)len, NULL); | |
SetupDiDestroyDeviceInfoList(devinfo); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment