From a8c0307aceff9f6471a9d821a9f851b4434fa097 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Mon, 14 Jun 2021 20:37:35 +1200 Subject: [PATCH] [WIP] Working basic adapter detection Need to begin to put this in the right places.... --- DisplayMagicianShared/AMD/ADL.cs | 9 +++++++++ DisplayMagicianShared/AMD/ADLWrapper.cs | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/DisplayMagicianShared/AMD/ADL.cs b/DisplayMagicianShared/AMD/ADL.cs index c5117c9..65847bf 100644 --- a/DisplayMagicianShared/AMD/ADL.cs +++ b/DisplayMagicianShared/AMD/ADL.cs @@ -244,6 +244,15 @@ namespace ATI.ADL /// Indicating the display info value. internal int DisplayInfoValue; } + + /// ADLDisplayInfo Array + [StructLayout(LayoutKind.Sequential)] + internal struct ADLDisplayInfoArray + { + /// ADLDisplayInfo Array + [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)ADL.ADL_MAX_DISPLAYS)] + internal ADLDisplayInfo[] ADLDisplayInfo; + } #endregion ADLDisplayInfo #region ADLSLS diff --git a/DisplayMagicianShared/AMD/ADLWrapper.cs b/DisplayMagicianShared/AMD/ADLWrapper.cs index 4da44b2..d6a61bd 100644 --- a/DisplayMagicianShared/AMD/ADLWrapper.cs +++ b/DisplayMagicianShared/AMD/ADLWrapper.cs @@ -80,14 +80,25 @@ namespace DisplayMagicianShared.AMD int j = 0; // Force the display detection and get the Display Info. Use 0 as last parameter to NOT force detection - ADLRet = ADL.ADL_Display_DisplayInfo_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref NumberOfDisplays, out DisplayBuffer, 1); + ADLRet = ADL.ADL_Display_DisplayInfo_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref NumberOfDisplays, out DisplayBuffer, 0); if (ADL.ADL_SUCCESS == ADLRet) { + List DisplayInfoData = new List(); - for (j = 0; j < NumberOfDisplays; j++) + + try { - oneDisplayInfo = (ADLDisplayInfo)Marshal.PtrToStructure(new IntPtr(DisplayBuffer.ToInt32() + j * Marshal.SizeOf(oneDisplayInfo)), oneDisplayInfo.GetType()); - DisplayInfoData.Add(oneDisplayInfo); + + for (j = 0; j < NumberOfDisplays; j++) + { + oneDisplayInfo = (ADLDisplayInfo)Marshal.PtrToStructure(new IntPtr(DisplayBuffer.ToInt64() + (j * Marshal.SizeOf(oneDisplayInfo))), oneDisplayInfo.GetType()); + DisplayInfoData.Add(oneDisplayInfo); + } + } + catch (Exception ex) + { + Console.WriteLine("Exception caused trying to access attached displays"); + continue; } Console.WriteLine("\nTotal Number of Displays supported: " + NumberOfDisplays.ToString()); Console.WriteLine("\nDispID AdpID Type OutType CnctType Connected Mapped InfoValue DisplayName ");