I am writing a program in Windows and I want to get the brightness of a computer monitor. I am using the Windows GetMonitorBrightness function, however I am having some trouble.
This is a snippet of my code so far:
HMONITOR hMonitor = NULL; DWORD cPhysicalMonitors; LPPHYSICAL_MONITOR pPhysicalMonitors = NULL; LPDWORD pdwMinimumBrightness=NULL; LPDWORD pdwCurrentBrightness=NULL; LPDWORD pdwMaximumBrightness=NULL; HWND hwnd = FindWindow(NULL, NULL); hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONULL); BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &cPhysicalMonitors); pPhysicalMonitors = (LPPHYSICAL_MONITOR)malloc(cPhysicalMonitors* sizeof(PHYSICAL_MONITOR)); bSuccess = GetPhysicalMonitorsFromHMONITOR(hMonitor, cPhysicalMonitors, pPhysicalMonitors); HANDLE pmh = pPhysicalMonitors.hPhysicalMonitor; bSuccess = GetMonitorBrightness(pmh, pdwMinimumBrightness, pdwCurrentBrightness, pdwMaximumBrightness);
I wrote this following the Microsoft documentation.
But when I run this code I get a COM error: ERROR_GRAPHICS_I2C_ERROR_TRANSMITTING_DATA (0xC0262582) - "An error occurred while transmitting data to the device on the I2C bus."
I have tried searching for solutions to this error but have not been able to find anything related to my situation, it is because of this I ask this question.
p.s. I have also posted this same question to StackOverflow.