I'm making some tests with the Monitor Configuration API and due to my needs I've got to use the low level functions.
I've got no problems when the monitor is correctly plugged and set, however, if the monitor is in stand-by or another input is selected whenever I try to call either one of the low level or high level methods I get an error and my monitor completely stops responding to any of its buttons, I need to cut its power source and reconnect it. Tested on two completely different hardware configurations, and the previous call to GetNumberOfPhysicalMonitorsFromHMONITOR is correctly returning all the values.
It seems the amount of people using this API can be counted with the fingers of one hand and doesn't talk about this case.
My code is written using VB.NET, and the API is declared as:
Private Class NativeMethods
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)>
Public Structure PHYSICAL_MONITOR
Public hPhysicalMonitor As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)>
Public szPhysicalMonitorDescription As String
End Structure
Public Enum LPMC_VCP_CODE_TYPE
MC_MOMENTARY
MC_SET_PARAMETER
End Enum
<DllImport("user32.dll", EntryPoint:="MonitorFromWindow")> _
Public Shared Function MonitorFromWindow(ByVal hwnd As System.IntPtr, ByVal dwFlags As UInteger) As System.IntPtr
End Function
<DllImport("dxva2.dll", EntryPoint:="GetNumberOfPhysicalMonitorsFromHMONITOR", SetLastError:=True)>
Public Shared Function GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor As IntPtr, ByRef pdwNumberOfPhysicalMonitors As UInteger) As Boolean
End Function
<DllImport("dxva2.dll", EntryPoint:="GetPhysicalMonitorsFromHMONITOR", SetLastError:=True)>
Public Shared Function GetPhysicalMonitorsFromHMONITOR(hMonitor As IntPtr, dwPhysicalMonitorArraySize As UInteger, <Out()> pPhysicalMonitorArray As PHYSICAL_MONITOR()) As Boolean
End Function
<DllImport("dxva2.dll", EntryPoint:="DestroyPhysicalMonitors", SetLastError:=True)>
Public Shared Function DestroyPhysicalMonitors(dwPhysicalMonitorArraySize As UInteger, pPhysicalMonitorArray As PHYSICAL_MONITOR()) As Boolean
End Function
<DllImport("dxva2.dll", EntryPoint:="GetCapabilitiesStringLength", SetLastError:=True)>
Public Shared Function GetCapabilitiesStringLength(hMonitor As IntPtr, <Out()> ByRef pdwCapabilitiesStringLengthInCharacters As UInteger) As Boolean
End Function
<DllImport("dxva2.dll", EntryPoint:="CapabilitiesRequestAndCapabilitiesReply", SetLastError:=True)>
Public Shared Function CapabilitiesRequestAndCapabilitiesReply(hMonitor As IntPtr, <Out(), MarshalAs(UnmanagedType.LPStr)> pszASCIICapabilitiesString As System.Text.StringBuilder, dwCapabilitiesStringLengthInCharacters
As UInteger) As Boolean
End Function
<DllImport("dxva2.dll", EntryPoint:="GetVCPFeatureAndVCPFeatureReply", SetLastError:=True)>
Public Shared Function GetVCPFeatureAndVCPFeatureReply(hMonitor As IntPtr, bVCPCode As Byte, <Out()> ByRef pvct As LPMC_VCP_CODE_TYPE, <Out()> ByRef pdwCurrentValue As UInteger, <Out()> ByRef pdwMaximumValue
As UInteger) As Boolean
End Function
<DllImport("dxva2.dll", EntryPoint:="SetVCPFeature", SetLastError:=True)>
Public Shared Function SetVCPFeature(hMonitor As IntPtr, bVCPCode As Byte, dwNewValue As UInteger) As Boolean
End Function
End Class
Anyway, I repeat, it works as expected when the monitor is not in stand mode and with the input source set to a different one. I could somewhat expect the API not to work otherwise (although I don't see the standards saying so), but not to completely freeze the control panel.
Has anyone else run into this problem or have some extra info to share?