/// <summary>
        /// Initializes a new instance of the <see cref="ProcessHandleResult"/> class. 
        /// </summary>
        /// <param name="handle">
        /// The device notification handle.
        /// </param>
        /// <param name="marshalWrapper">
        /// The marshal static class wrapper.
        /// </param>
        public ProcessHandleResult(IntPtr handle, IMarshalWrapper marshalWrapper)
        {
            Handle = handle;
            Win32Error = new Win32ErrorWrapper(0);
            if (handle != IntPtr.Zero)
            {
                return;
            }

            Win32Error = marshalWrapper.GetLastWin32Error();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessHandleResult"/> class.
        /// </summary>
        /// <param name="handle">
        /// The device notification handle.
        /// </param>
        /// <param name="marshalWrapper">
        /// The marshal static class wrapper.
        /// </param>
        public ProcessHandleResult(IntPtr handle, IMarshalWrapper marshalWrapper)
        {
            Handle     = handle;
            Win32Error = new Win32ErrorWrapper(0);
            if (handle != IntPtr.Zero)
            {
                return;
            }

            Win32Error = marshalWrapper.GetLastWin32Error();
        }
Example #3
0
        /// <summary>
        /// The get device interface detail.
        /// </summary>
        /// <param name="deviceInformationSetHandle">
        /// The device information set handle.
        /// </param>
        /// <param name="deviceInterfaceData">
        /// The device interface data.
        /// </param>
        /// <returns>
        /// The <see cref="DeviceInterfaceDetail"/>.
        /// </returns>
        public IDeviceInterfaceDetail GetDeviceInterfaceDetail(IntPtr deviceInformationSetHandle, DeviceInterfaceData deviceInterfaceData)
        {
            var bufferSize = 0;
            var success    = UnsafeNativeMethods.SetupDiGetDeviceInterfaceDetail(deviceInformationSetHandle, deviceInterfaceData, IntPtr.Zero, 0, ref bufferSize, IntPtr.Zero);
            var lastError  = _marshalWrapper.GetLastWin32Error();

            if (!success && lastError.IsInsufficientBuffer)
            {
                // TODO: Somehow we need to get rid of setting up properties of the deviceInterfacedetails and use them either direct and pass them into the constructor or think of another way.
                var deviceInterfaceDetails = _deviceInterfaceDetailFactory.Create(deviceInformationSetHandle, bufferSize);
                success = UnsafeNativeMethods.SetupDiGetDeviceInterfaceDetail(
                    deviceInformationSetHandle,
                    deviceInterfaceData,
                    deviceInterfaceDetails.DeviceInterfaceDetailBuffer,
                    bufferSize,
                    ref bufferSize,
                    deviceInterfaceDetails.DeviceInfoData);

                return(!success?_deviceInterfaceDetailFactory.CreateNull() : (IDeviceInterfaceDetail)deviceInterfaceDetails);
            }

            return(_deviceInterfaceDetailFactory.CreateNull());
        }