Example #1
1
        /// <summary>
        /// Helper method to return the device path given a DeviceInterfaceData structure and an InfoSet handle.
        /// Used in 'FindDevice' so check that method out to see how to get an InfoSet handle and a DeviceInterfaceData.
        /// </summary>
        /// <param name="hInfoSet">Handle to the InfoSet</param>
        /// <param name="oInterface">DeviceInterfaceData structure</param>
        /// <returns>The device path or null if there was some problem</returns>
        private static string GetDevicePath(IntPtr hInfoSet, ref SP_DEVICE_INTERFACE_DATA oInterface)
        {
            int nRequiredSize = 0;

            // Get the device interface details
            if (!Setup.SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, IntPtr.Zero, 0, ref nRequiredSize, IntPtr.Zero))
            {
                SP_DEVICE_INTERFACE_DETAIL_DATA oDetail = new SP_DEVICE_INTERFACE_DETAIL_DATA();
                oDetail.cbSize = 5;	// 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 (Setup.SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, ref oDetail, nRequiredSize, ref nRequiredSize, IntPtr.Zero))
                {
                    return oDetail.DevicePath;
                }
            }
            return null;
        }
Example #2
0
 public static extern Boolean SetupDiGetDeviceInterfaceDetail(IntPtr DeviceInfoSet, 
     ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
     ref SP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData, 
     Int32 DeviceInterfaceDetailDataSize, 
     ref Int32 RequiredSize, 
     IntPtr DeviceInfoData);