Use AMD ADL to acquire monitor EDID in C#

540 Views Asked by At

I am using the AMD ADL to enumerate and manipulate displays attached to my system. One of the necessary functions I need is the ability to read and parse the display EDID. I am able to parse a byte array representation of the EDID, however I am unable to acquire the EDID. Based on the ADL documentation, I have defined the ADLDisplayEDIDData struct and imported the ADL_Display_EdidData_Get function. However, any execution of my code results in an error of retvalue -3. This retvalue indicates invalid parameters.

The EDIDData structure:

[StructLayout(LayoutKind.Sequential)]
internal struct ADLDisplayEDIDData
{
    internal int Size;
    internal int Flag;
    internal int EDIDSize;
    internal int BlockIndex;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 255)]
    internal byte[] EDIDData;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
    internal int[] Reserved;
}

The DLLImport:

[DllImport(Atiadlxx_FileName)]
internal static extern int ADL_Display_EdidData_Get(int adapterIndex, int displayIndex, ref ADLDisplayEDIDData EDIDData);

Is there any error with my declarations? Does anyone have any experience with the ADL and getting the EDID information?

Thank you in advance.

1

There are 1 best solutions below

0
On

Try this:

[DllImport(Atiadlxx_FileName)]
internal static extern int ADL_Display_EdidData_Get(int adapterIndex, int displayIndex, [In, Out] ADLDisplayEDIDData[] EDIDData);

ADLDisplayEDIDData[] EDID = new ADLDisplayEDIDData[2];
NVGetMonitorEDIDs(0, EDID);

It would be good to pass the dimension length to c++ like this:

[DllImport(Atiadlxx_FileName)]
internal static extern int ADL_Display_EdidData_Get(int adapterIndex, int displayIndex, [In, Out] ADLDisplayEDIDData[] EDIDData, int iLength);

ADLDisplayEDIDData[] EDID = new ADLDisplayEDIDData[2];
NVGetMonitorEDIDs(0, EDID, EDID.Length);