示例#1
0
        public DeviceInterfaceDetail(IntPtr handle, DeviceInterfaceData did)
        {
            // build a DevInfo Data structure
            _deviceInfoData        = new DevInfoData();
            _deviceInfoData.cbSize = (uint)Marshal.SizeOf(_deviceInfoData);

            // build a Device Interface Detail Data structure
            _didd = new DeviceInterfaceDetailData();
            if (IntPtr.Size == 8) // for 64 bit operating systems
            {
                _didd.cbSize = 8;
            }
            else
            {
                _didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // for 32 bit systems
            }
            // now we can get some more detailed information
            uint       nRequiredSize;
            const uint nBytes = DeviceInterfaceDetailData.BufferSize;

            if (!SetupDiGetDeviceInterfaceDetail(handle, ref did, ref _didd, nBytes, out nRequiredSize, ref _deviceInfoData))
            {
                var lastError = Marshal.GetLastWin32Error();
                throw new Win32Exception(lastError, "SetupDiGetDeviceInterfaceDetail failed");
            }
        }
示例#2
0
 public static extern Boolean SetupDiGetDeviceInterfaceDetail(
     IntPtr hDevInfo,
     ref DeviceInterfaceData deviceInterfaceData,
     ref DeviceInterfaceDetailData deviceInterfaceDetailData,
     UInt32 deviceInterfaceDetailDataSize,
     out UInt32 requiredSize,
     ref DevInfoData deviceInfoData
     );
 public static extern Boolean SetupDiGetDeviceInterfaceDetail(
     IntPtr hDevInfo,
     ref DeviceInterfaceData deviceInterfaceData,
     ref DeviceInterfaceDetailData deviceInterfaceDetailData,
     UInt32 deviceInterfaceDetailDataSize,
     out UInt32 requiredSize,
     ref DevInfoData deviceInfoData
     );
        public DeviceInterfaceDetail(IntPtr handle, DeviceInterfaceData did)
        {
            // build a DevInfo Data structure
            _deviceInfoData = new DevInfoData();
            _deviceInfoData.cbSize = (uint)Marshal.SizeOf(_deviceInfoData);

            // build a Device Interface Detail Data structure
            _didd = new DeviceInterfaceDetailData();
            if (IntPtr.Size == 8) // for 64 bit operating systems
                _didd.cbSize = 8;
            else
                _didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // for 32 bit systems

            // now we can get some more detailed information
            uint nRequiredSize;
            const uint nBytes = DeviceInterfaceDetailData.BufferSize;
            if (!SetupDiGetDeviceInterfaceDetail(handle, ref did, ref _didd, nBytes, out nRequiredSize, ref _deviceInfoData))
            {
                var lastError = Marshal.GetLastWin32Error();
                throw new Win32Exception(lastError, "SetupDiGetDeviceInterfaceDetail failed");
            }
        }
 /// <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="interfaceData">DeviceInterfaceData structure</param>
 /// <returns>The device path or null if there was some problem</returns>
 private static string GetDevicePath(IntPtr hInfoSet, ref DeviceInterfaceData oInterface)
 {
     uint nRequiredSize = 0;
     // Get the device interface details
     if (!SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, IntPtr.Zero, 0, ref nRequiredSize, IntPtr.Zero))
     {
         DeviceInterfaceDetailData oDetail = new DeviceInterfaceDetailData();
         oDetail.Size = 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 (SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, ref oDetail, nRequiredSize, ref nRequiredSize, IntPtr.Zero))
         {
             return oDetail.DevicePath;
         }
     }
     return null;
 }
示例#6
0
 protected static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr lpDeviceInfoSet, ref DeviceInterfaceData oInterfaceData, ref DeviceInterfaceDetailData oDetailData, uint nDeviceInterfaceDetailDataSize, ref uint nRequiredSize, IntPtr lpDeviceInfoData);