/* get device path */ private static string GetPath(IntPtr hInfoSet, ref Native.DeviceInterfaceData iface) { /* detailed interface information */ var detIface = new Native.DeviceInterfaceDetailData(); /* required size */ uint reqSize = (uint)Marshal.SizeOf(detIface); /* set size. The cbSize member always contains the size of the * fixed part of the data structure, not a size reflecting the * variable-length string at the end. */ /* now stay with me and look at that x64/x86 maddness! */ detIface.Size = Marshal.SizeOf(typeof(IntPtr)) == 8 ? 8 : 5; /* get device path */ bool status = Native.SetupDiGetDeviceInterfaceDetail(hInfoSet, ref iface, ref detIface, reqSize, ref reqSize, IntPtr.Zero); /* whops */ if (!status) { /* fail! */ throw new Win32Exception(); } /* return device path */ return detIface.DevicePath; }