/// <summary> /// Validate the header and CRC-32 of this structure. /// </summary> /// <returns>True if the structure is valid.</returns> /// <remarks></remarks> public bool Validate() { bool ValidateRet = default; var mm = new MemPtr(); mm.FromStruct(this); mm.UIntAt(4L) = 0U; // validate the crc and the signature moniker ValidateRet = HeaderCRC32 == mm.CalculateCrc32() && Signature == 0x5452415020494645; mm.Free(); return(ValidateRet); }
/// <summary> /// Enumerate all display monitors. /// </summary> /// <returns>An array of PrinterDeviceInfo objects.</returns> /// <remarks></remarks> public static MonitorDeviceInfo[] EnumMonitors() { var minf = _internalEnumerateDevices <MonitorDeviceInfo>(DevProp.GUID_DEVINTERFACE_MONITOR, ClassDevFlags.DeviceInterface | ClassDevFlags.Present); var mon = new Monitors(); DISPLAY_DEVICE dd; dd.cb = (uint)Marshal.SizeOf <DISPLAY_DEVICE>(); var mm = new MemPtr(); mm.Alloc(dd.cb); mm.UIntAt(0) = dd.cb; if (minf is object && minf.Count() > 0) { foreach (var x in minf) { foreach (var y in mon) { if (MultiMon.EnumDisplayDevices(y.DevicePath, 0, mm, MultiMon.EDD_GET_DEVICE_INTERFACE_NAME)) { dd = mm.ToStruct <DISPLAY_DEVICE>(); DEVMODE dev = new DEVMODE(); dev.dmSize = (ushort)Marshal.SizeOf <DEVMODE>(); dev.dmDriverExtra = 0; var mm2 = new MemPtr(65535 + dev.dmSize); var b = MultiMon.EnumDisplaySettingsEx(y.DevicePath, 0xffffffff, ref dev, 0); if (!b) { var s = NativeErrorMethods.FormatLastError(); } mm2.Free(); if (dd.DeviceID.ToUpper() == x.DevicePath.ToUpper()) { x.Source = y; break; } } } } } mm.Free(); if (minf is null) { return(null); } Array.Sort(minf, new Comparison <MonitorDeviceInfo>((x, y) => { if (x.FriendlyName is object && y.FriendlyName is object) { return(string.Compare(x.FriendlyName, y.FriendlyName)); } else { return(string.Compare(x.Description, y.Description)); } })); return(minf); }