Как вызвать «GetNumberOfPhysicalMonitorsFromHMONITOR» dxva2.dll из службы Windows - PullRequest
0 голосов
/ 18 февраля 2019

Мне нужно реализовать некоторые операции отображения, основанные на API-интерфейсе Windows dxva2.dll

Ниже код работает нормально, пока я работаю в качестве приложения Windows, но он всегда возвращает false при регистрации его в качестве службы Windows

[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!");
     }
}


...