dll 方法:
int ADL_Display_DisplayMapConfig_Get (int iAdapterIndex, int *lpNumDisplayMap, **lppDisplayMap, int *lpNumDisplayTarget, **lppDisplayTarget, int iOptions);
C#调用:
[DllImport("abc.dll")]
public static extern int ADL_Display_DisplayMapConfig_Get(int iAdapterIndex, ref int lpNumDisplayMap, out IntPtr lppDisplayMap, ref int lpNumDisplayTarget, out IntPtr lppDisplayTarget, int iOptions);
调用后读取返回值:
List<ADLDisplayMap> mapList = new List<ADLDisplayMap>();
ADLDisplayMap map = new ADLDisplayMap();
for (int i = 0; i < iNumDisplayMap; i++)
{
map = (ADLDisplayMap)Marshal.PtrToStructure(new IntPtr(pDisplayMap.ToInt32() + i * Marshal.SizeOf(map)), map.GetType());
mapList.Add(map);
}
List<ADLDisplayTarget> targetList = new List<ADLDisplayTarget>();
ADLDisplayTarget target = new ADLDisplayTarget();
for (int i = 0; i < iNumDisplayTarget; i++)
{
target = (ADLDisplayTarget)Marshal.PtrToStructure(new IntPtr(pDisplayTarget.ToInt32() + i * Marshal.SizeOf(target)), target.GetType());
targetList.Add(target);
}
指针普通应用情况
ADLMode mode = new ADLMode();
IntPtr pTransientModes = IntPtr.Zero;
pTransientModes = Marshal.AllocCoTaskMem(Marshal.SizeOf(mode));
Marshal.StructureToPtr(mode, pTransientModes, false);
mode= (ADLMode)Marshal.PtrToStructure(pTransientModes, mode.GetType());
获取数组的指针
ADLSLSOffset[] appliedBezelOffsets = new ADLSLSOffset[n];
lpAppliedBezelOffsets = Marshal.UnsafeAddrOfPinnedArrayElement(appliedBezelOffsets, 0);