internal Guid GetProperty(Native.SP_DEVINFO_DATA devData, int property, Guid defaultValue) { if (devData == null) { throw new ArgumentNullException("devData"); } int propertyRegDataType = 0; int requiredSize; int propertyBufferSize = Marshal.SizeOf(typeof(Guid)); IntPtr propertyBuffer = Marshal.AllocHGlobal(propertyBufferSize); if (!Native.SetupDiGetDeviceRegistryProperty(_deviceInfoSet, devData, property, out propertyRegDataType, propertyBuffer, propertyBufferSize, out requiredSize)) { Marshal.FreeHGlobal(propertyBuffer); int error = Marshal.GetLastWin32Error(); if (error != Native.ERROR_INVALID_DATA) { throw new Win32Exception(error); } return(defaultValue); } Guid value = (Guid)Marshal.PtrToStructure(propertyBuffer, typeof(Guid)); Marshal.FreeHGlobal(propertyBuffer); return(value); }
internal Device(DeviceClass deviceClass, Native.SP_DEVINFO_DATA deviceInfoData, string path, int index) { if (deviceClass == null) { throw new ArgumentNullException("deviceClass"); } if (deviceInfoData == null) { throw new ArgumentNullException("deviceInfoData"); } _deviceClass = deviceClass; _path = path; // may be null _deviceInfoData = deviceInfoData; _index = index; }
internal Native.SP_DEVINFO_DATA GetInfo(int dnDevInst) { StringBuilder sb = new StringBuilder(1024); int hr = Native.CM_Get_Device_ID(dnDevInst, sb, sb.Capacity, 0); if (hr != 0) { throw new Win32Exception(hr); } Native.SP_DEVINFO_DATA devData = new Native.SP_DEVINFO_DATA(); devData.cbSize = Marshal.SizeOf(typeof(Native.SP_DEVINFO_DATA)); if (!Native.SetupDiOpenDeviceInfo(_deviceInfoSet, sb.ToString(), IntPtr.Zero, 0, devData)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return(devData); }
internal virtual Device CreateDevice(DeviceClass deviceClass, Native.SP_DEVINFO_DATA deviceInfoData, string path, int index) { return(new Device(deviceClass, deviceInfoData, path, index)); }
internal override Device CreateDevice(DeviceClass deviceClass, Native.SP_DEVINFO_DATA deviceInfoData, string path, int index) { return(new Volume(deviceClass, deviceInfoData, path, index)); }
internal Volume(DeviceClass deviceClass, Native.SP_DEVINFO_DATA deviceInfoData, string path, int index) : base(deviceClass, deviceInfoData, path, index) { }