private static IEnumerable <PartialScreenInfo> GetSetupApiData() { var screenInfos = new List <PartialScreenInfo>(); var monitorGuid = NativeMethods.GUID_DEVINTERFACE_MONITOR; var devInfoSetHandle = IntPtr.Zero; try { devInfoSetHandle = NativeMethods.SetupDiGetClassDevs( ref monitorGuid, null, IntPtr.Zero, NativeMethods.DiGetClassFlags.DIGCF_PRESENT | NativeMethods.DiGetClassFlags.DIGCF_DEVICEINTERFACE); if (devInfoSetHandle == IntPtr.Zero) { throw new Win32Exception(); } uint i = 0; while (true) { var deviceInterfaceData = new NativeMethods.SP_DEVICE_INTERFACE_DATA(); deviceInterfaceData.cbSize = Marshal.SizeOf(deviceInterfaceData); if (!NativeMethods.SetupDiEnumDeviceInterfaces( devInfoSetHandle, IntPtr.Zero, ref monitorGuid, i, ref deviceInterfaceData)) { if (Marshal.GetLastWin32Error() == NativeMethods.ERROR_NO_MORE_ITEMS) { break; } throw new Win32Exception(); } var deviceInterfaceDetail = GetDeviceInterfaceDetail(devInfoSetHandle, ref deviceInterfaceData); var screenInfo = new PartialScreenInfo( deviceInterfaceDetail.DevicePath, GetDeviceInstanceId(deviceInterfaceDetail.DevinfoData.DevInst), GetMonitorEDID(devInfoSetHandle, deviceInterfaceDetail.DevinfoData)); screenInfos.Add(screenInfo); i++; } } finally { if (devInfoSetHandle != IntPtr.Zero) { NativeMethods.SetupDiDestroyDeviceInfoList(devInfoSetHandle); } } return(screenInfos); }
private static IEnumerable<PartialScreenInfo> GetSetupApiData() { var screenInfos = new List<PartialScreenInfo>(); var monitorGuid = NativeMethods.GUID_DEVINTERFACE_MONITOR; var devInfoSetHandle = IntPtr.Zero; try { devInfoSetHandle = NativeMethods.SetupDiGetClassDevs( ref monitorGuid, null, IntPtr.Zero, NativeMethods.DiGetClassFlags.DIGCF_PRESENT | NativeMethods.DiGetClassFlags.DIGCF_DEVICEINTERFACE); if (devInfoSetHandle == IntPtr.Zero) { throw new Win32Exception(); } uint i = 0; while (true) { var deviceInterfaceData = new NativeMethods.SP_DEVICE_INTERFACE_DATA(); deviceInterfaceData.cbSize = Marshal.SizeOf(deviceInterfaceData); if (!NativeMethods.SetupDiEnumDeviceInterfaces( devInfoSetHandle, IntPtr.Zero, ref monitorGuid, i, ref deviceInterfaceData)) { if (Marshal.GetLastWin32Error() == NativeMethods.ERROR_NO_MORE_ITEMS) { break; } throw new Win32Exception(); } var deviceInterfaceDetail = GetDeviceInterfaceDetail(devInfoSetHandle, ref deviceInterfaceData); var screenInfo = new PartialScreenInfo( deviceInterfaceDetail.DevicePath, GetDeviceInstanceId(deviceInterfaceDetail.DevinfoData.DevInst), GetMonitorEDID(devInfoSetHandle, deviceInterfaceDetail.DevinfoData)); screenInfos.Add(screenInfo); i++; } } finally { if (devInfoSetHandle != IntPtr.Zero) { NativeMethods.SetupDiDestroyDeviceInfoList(devInfoSetHandle); } } return screenInfos; }