Beispiel #1
0
        /* get device path */
        private string GetPath(IntPtr hInfoSet, ref DeviceInterfaceData iface)
        {
            /* detailed interface information */
            var detIface = new 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 = HIDNativeAPIs.SetupDiGetDeviceInterfaceDetail(hInfoSet, ref iface, ref detIface, reqSize, ref reqSize, IntPtr.Zero);

            /* whops */
            if (!status)
            {
                /* fail! */
                throw new Win32Exception();
            }

            /* return device path */
            return(detIface.DevicePath);
        }
Beispiel #2
0
 public static extern bool SetupDiGetDeviceInterfaceDetail(
     IntPtr lpDeviceInfoSet, ref DeviceInterfaceData oInterfaceData,
     ref DeviceInterfaceDetailData oDetailData,
     uint nDeviceInterfaceDetailDataSize, ref uint nRequiredSize,
     IntPtr lpDeviceInfoData);