0

i'm try to get monitors info in my class and get C3867 error

BOOL CALLBACK myclass::monitors(_In_ HMONITOR hMonitor,_In_ HDC DevC,_In_ LPRECT lprcMonitor,_In_ LPARAM dwData)
{
...
}


void myclass::get_monitors_info()
{
 HDC hScreenDC = GetDC(NULL);
 EnumDisplayMonitors(hScreenDC, NULL, this->monitors, 0); //get C3867 error
...
}

if i try this, i'm get C2276 error

EnumDisplayMonitors(hScreenDC, NULL, &this->monitors, 0); //get C2276 error

if i implement this without class it works fine.

how make it work using classes?

  • Generally, you can't really use a non-static class member function as a callback. The problem lies in passing that function's address. See here: https://stackoverflow.com/q/1485983/10871073. There may be other/better examples, or even a duplicate ... – Adrian Mole May 21 '21 at 12:52
  • if i mark this function as static then all variables in must be static. it is unacceptably – user8763613 May 22 '21 at 05:12
  • @user8763613 You use the last param to `EnumDisplayMonitors` (now set to `0`) to pass additional data to the callback, for example the `this` pointer of the instance that called it. Then the static callback can access that instance. – dxiv May 22 '21 at 07:00

0 Answers0