private static string SetupDiGetDeviceProperty(IntPtr deviceInfoSet, ref SpDevInfoData deviceInfoData, DevPropKey propertyKey) { var localPropertyKey = propertyKey; uint propertyType; var buffer = new byte[0]; uint requiredSize; // First call retrieves the necessary buffer size SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, ref localPropertyKey, out propertyType, buffer, (uint)buffer.Length, out requiredSize, 0); var err = Marshal.GetLastWin32Error(); if (err != ERROR_INSUFICCIENT_BUFFER) { throw Marshal.GetExceptionForHR(Win32ErrorToHResult(err)); } buffer = new byte[requiredSize]; if (!SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, ref localPropertyKey, out propertyType, buffer, (uint)buffer.Length, out requiredSize, 0)) { throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); } // We only understand strings. if (propertyType != DEVPROP_TYPE_STRING) { throw new NotSupportedException("Unknown property type " + propertyType); } return(Encoding.Unicode.GetString(buffer).TrimEnd('\0')); }
void GetSizeForDisplayDevices(List <Models.Monitor> monitors, CancellationToken token) { IntPtr devInfo = _nativeMethods.SetupDiGetClassDevsEx(new[] { NativeConstants.MonitorClassId }, null, IntPtr.Zero, NativeConstants.DIGCF_PRESENT | NativeConstants.DIGCF_PROFILE, IntPtr.Zero, null, IntPtr.Zero); if (devInfo == IntPtr.Zero) { return; } for (uint i = 0; ShouldDisplayDeviceLoopContinue(token); ++i) { var devInfoData = new SpDevInfoData { Size = (uint)_marshal.SizeOf <SpDevInfoData>() }; if (!_nativeMethods.SetupDiEnumDeviceInfo(devInfo, i, ref devInfoData)) { continue; } var instanceId = new char[NativeConstants.MAX_PATH]; if (!_nativeMethods.SetupDiGetDeviceInstanceId(devInfo, ref devInfoData, instanceId, NativeConstants.MAX_PATH, IntPtr.Zero)) { continue; } var instanceIdSize = Array.IndexOf(instanceId, '\0'); var instanceIdString = new string(instanceId, 0, instanceIdSize > 0 ? instanceIdSize : instanceId.Length); var monitor = monitors.Find(m => instanceIdString.Contains(Helpers.GetDeviceId(m.Id))); if (monitor == null) { continue; } IntPtr edidRegKey = _nativeMethods.SetupDiOpenDevRegKey(devInfo, ref devInfoData, NativeConstants.DICS_FLAG_GLOBAL, 0, NativeConstants.DIREG_DEV, NativeConstants.KEY_READ); if (edidRegKey != NativeConstants.INVALID_HANDLE_VALUE) { var edid = GetMonitorEdidFromRegistry(edidRegKey); if (edid.Length > 0) { monitor.Edid = _edidFactory.Create(edid); monitor.Dimensions = Helpers.GetMonitorSizeFromEdid(edid); } } _nativeMethods.RegCloseKey(edidRegKey); } _nativeMethods.SetupDiDestroyDeviceInfoList(devInfo); }
public static extern bool SetupDiGetDeviceProperty([In] IntPtr deviceInfoSet, [In, Out] ref SpDevInfoData deviceInfoData, [In, Out] ref DevPropKey propertyKey, [Out] out int propertyType, [In, Out] IntPtr propertyBuffer, [In] int propertyBufferSize, [Out] out int requiredSize, [In, Optional] int flags);
private static void SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, out SpDevInfoData deviceInfoData) { // This wrapper only enumerates the first device in the device info set. deviceInfoData = new SpDevInfoData { cbSize = (uint)Marshal.SizeOf(typeof(SpDevInfoData)) }; if (!SetupDiEnumDeviceInfo(deviceInfoSet, 0, ref deviceInfoData)) { throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); } }
public static extern IntPtr SetupDiOpenDevRegKey(IntPtr hDeviceInfoSet, SpDevInfoData deviceInfoData, uint scope, uint hwProfile, uint parameterRegistryValueKind, uint samDesired);
public static extern bool SetupDiSetDeviceRegistryProperty(IntPtr deviceInfoSet, SpDevInfoData devInfoData, int property, byte[] propertyBuffer, int propertyBufferSize);
public static extern bool SetupDiEnumDeviceInterfaces(IntPtr deviceInfoSet, SpDevInfoData deviceInfoData, ref Guid interfaceClassGuid, uint memberIndex, SpDeviceInterfaceData deviceInterfaceData);
public static extern bool SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, uint memberIndex, SpDevInfoData deviceInfoData);
internal static extern IntPtr SetupDiOpenDevRegKey(IntPtr deviceInfoSet, ref SpDevInfoData deviceInfoData, uint scope, uint hwProfile, uint keyType, uint samDesired);
public static extern bool SetupDiGetDeviceInstanceId(IntPtr deviceInfoSet, SpDevInfoData devInfoData, [Out] byte[] deviceInstanceIdBuffer, int deviceInstanceIdSize, out int requiredSize);
public static extern bool SetupDiEnumDeviceInfo([In] IntPtr deviceInfoSet, [In] int memberIndex, [In, Out] ref SpDevInfoData deviceInfoData);
public IntPtr SetupDiOpenDevRegKey(IntPtr deviceInfoSet, ref SpDevInfoData deviceInfoData, uint scope, uint hwProfile, uint keyType, uint samDesired) { return(NativeMethods.SetupDiOpenDevRegKey(deviceInfoSet, ref deviceInfoData, scope, hwProfile, keyType, samDesired)); }
public bool SetupDiGetDeviceInstanceId(IntPtr deviceInfoSet, ref SpDevInfoData deviceInfoData, char[] deviceInstanceId, uint deviceInstanceIdSize, IntPtr requiredSize) { return(NativeMethods.SetupDiGetDeviceInstanceId(deviceInfoSet, ref deviceInfoData, deviceInstanceId, deviceInstanceIdSize, requiredSize)); }
public bool SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, uint memberIndex, ref SpDevInfoData deviceInfoData) { return(NativeMethods.SetupDiEnumDeviceInfo(deviceInfoSet, memberIndex, ref deviceInfoData)); }
private static extern bool SetupDiGetDeviceProperty(IntPtr deviceInfoSet, [In] ref SpDevInfoData deviceInfoData, [In] ref DevPropKey propertyKey, out uint propertyType, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)][Out] byte[] buffer, uint bufferSize, out uint requiredSize, uint flags);
public static extern bool SetupDiGetDeviceRegistryProperty(IntPtr deviceInfoSet, SpDevInfoData devInfoData, int property, out int regDataType, [Out] byte[] propertyBuffer, int propertyBufferSize, out int requiredSize);
public static extern bool SetupDiGetDeviceRegistryProperty(IntPtr deviceInfoSet, SpDevInfoData deviceInfoData, uint property, uint propertyRegDataType, StringBuilder propertyBuffer, uint propertyBufferSize, out uint requiredSize);
public static extern bool SetupDiEnumDeviceInfo(SafeDeviceInfoSetHandle DeviceInfoSet, uint MemberIndex, ref SpDevInfoData DeviceInfoData);
internal static extern bool SetupDiGetDeviceInstanceId(IntPtr deviceInfoSet, ref SpDevInfoData deviceInfoData, char[] deviceInstanceId, uint deviceInstanceIdSize, IntPtr requiredSize);
private static extern bool SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, uint memberIndex, ref SpDevInfoData deviceInfoData);