public static extern unsafe int SetupDiGetDeviceInterfaceDetail( int DeviceInfoSet, ref UsbNativeType.SP_DEVICE_INTERFACE_DATA lpDeviceInterfaceData, ref UsbNativeType.PSP_DEVICE_INTERFACE_DETAIL_DATA myPSP_DEVICE_INTERFACE_DETAIL_DATA, int detailSize, ref int requiredSize, int *bPtr);
private unsafe static string GetDevicePath(UsbNativeType.GUID guid, int hardwareDevInfo, int device_number) { int result = 0; UsbNativeType.SP_DEVICE_INTERFACE_DATA interfaceData = new UsbNativeType.SP_DEVICE_INTERFACE_DATA(); interfaceData.cbSize = Marshal.SizeOf(interfaceData); // get the device_number device interface result = UsbNativeApi.SetupDiEnumDeviceInterfaces( hardwareDevInfo, 0, ref guid, device_number, ref interfaceData); // get the required size for the device interface system path int devicePathSize = 0; result = UsbNativeApi.SetupDiGetDeviceInterfaceDetail( hardwareDevInfo, // IN HDEVINFO DeviceInfoSet, ref interfaceData, // IN PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, null, // DeviceInterfaceDetailData, OPTIONAL 0, // IN DWORD DeviceInterfaceDetailDataSize, ref devicePathSize, // OUT PDWORD RequiredSize, OPTIONAL null); // // get the actual device interface details UsbNativeType.PSP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetail = new UsbNativeType.PSP_DEVICE_INTERFACE_DETAIL_DATA(); interfaceDetail.cbSize = 5; // sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA) == 5 in C result = UsbNativeApi.SetupDiGetDeviceInterfaceDetail( hardwareDevInfo, // IN HDEVINFO DeviceInfoSet, ref interfaceData, // IN PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, ref interfaceDetail, // DeviceInterfaceDetailData, OPTIONAL devicePathSize, // IN DWORD DeviceInterfaceDetailDataSize, ref devicePathSize, // OUT PDWORD RequiredSize, OPTIONAL null); // return(interfaceDetail.DevicePath); }
public static extern unsafe int SetupDiEnumDeviceInterfaces( int DeviceInfoSet, int DeviceInfoData, ref UsbNativeType.GUID lpHidGuid, int MemberIndex, ref UsbNativeType.SP_DEVICE_INTERFACE_DATA lpDeviceInterfaceData);