MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / hid_winapi_get_container_id

Function hid_winapi_get_container_id

lib/hidapi/windows/hid.c:1370–1419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1368}
1369
1370int HID_API_EXPORT_CALL hid_winapi_get_container_id(hid_device *dev, GUID *container_id)
1371{
1372 wchar_t *interface_path = NULL, *device_id = NULL;
1373 CONFIGRET cr = CR_FAILURE;
1374 DEVINST dev_node;
1375 DEVPROPTYPE property_type;
1376 ULONG len;
1377
1378 if (!container_id) {
1379 register_string_error(dev, L"Invalid Container ID");
1380 return -1;
1381 }
1382
1383 register_string_error(dev, NULL);
1384
1385 interface_path = hid_internal_UTF8toUTF16(dev->device_info->path);
1386 if (!interface_path) {
1387 register_string_error(dev, L"Path conversion failure");
1388 goto end;
1389 }
1390
1391 /* Get the device id from interface path */
1392 device_id = hid_internal_get_device_interface_property(interface_path, &DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING);
1393 if (!device_id) {
1394 register_string_error(dev, L"Failed to get device interface property InstanceId");
1395 goto end;
1396 }
1397
1398 /* Open devnode from device id */
1399 cr = CM_Locate_DevNodeW(&dev_node, (DEVINSTID_W)device_id, CM_LOCATE_DEVNODE_NORMAL);
1400 if (cr != CR_SUCCESS) {
1401 register_string_error(dev, L"Failed to locate device node");
1402 goto end;
1403 }
1404
1405 /* Get the container id from devnode */
1406 len = sizeof(*container_id);
1407 cr = CM_Get_DevNode_PropertyW(dev_node, &DEVPKEY_Device_ContainerId, &property_type, (PBYTE)container_id, &len, 0);
1408 if (cr == CR_SUCCESS && property_type != DEVPROP_TYPE_GUID)
1409 cr = CR_FAILURE;
1410
1411 if (cr != CR_SUCCESS)
1412 register_string_error(dev, L"Failed to read ContainerId property from device node");
1413
1414end:
1415 free(interface_path);
1416 free(device_id);
1417
1418 return cr == CR_SUCCESS ? 0 : -1;
1419}
1420
1421
1422int HID_API_EXPORT_CALL hid_get_report_descriptor(hid_device *dev, unsigned char *buf, size_t buf_size)

Callers

nothing calls this directly

Tested by

no test coverage detected