我需要基于dxva2.dll Windows API实现一些显示操作
下面的代码作为Windows应用程序运行时可以正常工作,但是将其注册为Windows服务时始终返回false
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetNumberOfPhysicalMonitorsFromHMONITOR(IntPtr hMonitor, ref uint pdwNumberOfPhysicalMonitors);`
[DllImport("dxva2.dll", EntryPoint = "GetPhysicalMonitorsFromHMONITOR")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPhysicalMonitorsFromHMONITOR(IntPtr hMonitor, uint dwPhysicalMonitorArraySize, [Out] PhysicalMonitor[] pPhysicalMonitorArray);`
public void Sample()
{
if (!GetNumberOfPhysicalMonitorsFromHMONITOR(monitor.MonitorHandle, ref
_physicalMonitorsCount))
{
throw new Exception("Cannot get monitor count!");
}
if (!GetPhysicalMonitorsFromHMONITOR(monitor.MonitorHandle,
_physicalMonitorsCount, _physicalMonitorArray))
{
throw new Exception("Cannot get physical monitor handle!");
}
}