private static string GetDevicePath(IntPtr hInfoSet, ref DeviceInterfaceData oInterface)
{
uint nRequiredSize = 0;
DeviceInfoData da = new DeviceInfoData();
da.Size = (uint)Marshal.SizeOf(da);
// Get the device interface details
if (!SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, IntPtr.Zero, 0, ref nRequiredSize, ref da))
{
DeviceInterfaceDetailData oDetail = new DeviceInterfaceDetailData();
oDetail.Size = (IntPtr.Size == 4) ? 5 : 8; // hardcoded to 5! Sorry, but this works and trying more future proof versions by setting the size to the struct sizeof failed miserably. If you manage to sort it, mail me! Thx
if (SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, ref oDetail, nRequiredSize, ref nRequiredSize, ref da))
{
return oDetail.DevicePath;
}
}
return null;
}