如何在 Delphi 中编写PHYSICAL_MONITOR数组?

bxpogfeg  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(103)

我正在尝试让 Delphi 与WinAPI函数GetPhysicalMonitorsFromHMONITOR()对话。
如何设置所需的数据结构?
目前,我有:

LPPHYSICAL_MONITOR = record
    hPhysicalMonitor: THandle;
    szPhysicalMonitorDescription: array [0..127] of WideChar;
  end;
  PLPPHYSICAL_MONITOR = ^LPPHYSICAL_MONITOR;

字符串
然而,函数需要一个数组-而我需要一个数组,当我解引用Pointer结构以获得第一个,第二个...监视器时。
这就是我对函数本身的理解:

function GetPhysicalMonitorsFromHMONITOR(hMonitor: HMONITOR;
   dwPhysicalMonitorArraySize: DWORD;
   pPhysicalMonitorArray: PLPPHYSICAL_MONITOR): Boolean;
   stdcall; external 'Dxva2.dll' Name 'GetPhysicalMonitorsFromHMONITOR';

uubf1zoe

uubf1zoe1#

根据您链接到的相同文档:
要获得所需的数组大小,请调用GetNumberOfPhysicalMonitorsFromHMONITOR
因此,首先获取数组大小,然后分配数组,然后将数组传递给GetPhysicalMonitorsFromHMONITOR()。您链接到的同一文档甚至提供了一个示例(在C中,可以很容易地翻译为 Delphi )。
请尝试以下操作:

const
  PHYSICAL_MONITOR_DESCRIPTION_SIZE = 128;

type
  PHYSICAL_MONITOR = record
    hPhysicalMonitor: THandle;
    szPhysicalMonitorDescription: array[0..PHYSICAL_MONITOR_DESCRIPTION_SIZE-1] of WideChar;
  end;
  LPPHYSICAL_MONITOR = ^PHYSICAL_MONITOR;

function GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor: HMONITOR;
  pdwNumberOfPhysicalMonitors: LPDWORD): BOOL;
  stdcall; external 'Dxva2.dll' name 'GetNumberOfPhysicalMonitorsFromHMONITOR';

function GetPhysicalMonitorsFromHMONITOR(hMonitor: HMONITOR;
  dwPhysicalMonitorArraySize: DWORD;
  pPhysicalMonitorArray: LPPHYSICAL_MONITOR): BOOL;
  stdcall; external 'Dxva2.dll' name 'GetPhysicalMonitorsFromHMONITOR';

function DestroyPhysicalMonitors(dwPhysicalMonitorArraySize: DWORD;
  LPPHYSICAL_MONITOR pPhysicalMonitorArray): _BOOL;
  stdcall; external 'Dxva2.dll' name 'DestroyPhysicalMonitors';

个字符

相关问题