0

I am developing a 64 bit console application using Visual studio on a Windows 10 computer, using the Windows SDK version 10.0.17134.0

I am trying to get the monitor brightness values using the the GetMonitorBrightness API. The code for the same is as follows:

HWND hwnd = GetForegroundWindow();

HMONITOR hmonitor;
hmonitor = MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTOPRIMARY);
DWORD min, curr, max;
if (GetMonitorBrightness(hmonitor,&min,&curr,&max))
{
    cout << ": The error code is  " << GetLastError() << endl;

}
    cout << ": The error code is  " << GetLastError() << endl; 

getchar();
return 0;

I am getting the following error: LNK2019 unresolved external symbol GetMonitorBrightness referenced in function main

I have also included the correct header file i.e., highlevelmonitorconfigurationapi.h.

And my monitors are DDC/CI enabled too.

Any idea how I can fix the error for the above mentioned API?

Wolverine
  • 51
  • 7
  • 5
    1) "_I have also included the correct header file_" Linker doesn't care about header files. Only compiler cares about those. 2) You can fix it, by linking to the correct library. – Algirdas Preidžius Jun 07 '18 at 14:42

1 Answers1

0

According to MSDN, you need to link Dxva2.lib to your executable.

You should be able to do it within source file after headers declaration by using pragma like this:

#pragma comment(lib, "Dxva2.lib")
rkosegi
  • 14,165
  • 5
  • 50
  • 83