如何从Windows服务调用dxva2.dll的“ GetNumberOfPhysicalMonitorsFromHMONITOR”

时间:2019-02-18 12:27:38

标签: c# windows-services dxva

我需要基于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!");
     }
}


0 个答案:

没有答案