pointer to callback function

Hello everyone,
I'm trying to use the EnumWindowStations function from the WinUser.h library but I can't pass it the pointer to the callback function I created. That is, it is not clear to me how it should do it and I cannot clarify my ideas on this problem despite the fact that I have studied the references to this function.
( https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumwindowstationsw )

My code:

BOOL CALLBACK CWinLogon::EnumWindowStationProc(__in LPWSTR lpszWindowStation,__in LPARAM lParam)
{
...
return true;
}
void MyFunction()
{
if ( EnumWindowStations(&EnumWindowStationProc, NULL) )
home_window_station = 0;
}
I receive this error:
the argument of type "BOOL (__stdcall *) (LPWSTR lpszWindowStation, LPARAM lParam)" is incompatible with the type parameter "WINSTAENUMPROCW"

now going to see the definitions on the WinUser.h file
code:

typedef BOOL (CALLBACK* NAMEENUMPROCW)(LPWSTR, LPARAM);
typedef NAMEENUMPROCW WINSTAENUMPROCW;
typedef WINSTAENUMPROCW WINSTAENUMPROC;

At this point I'm stuck, I can't figure out how to pass the EnumWindowStationProc function to EnumWindowStations.
Can anyone clarify my ideas?
Thanks so much


Last edited on
You cannot pass a non static member function this way. If it is static you would pass it like so:

1
2
if ( EnumWindowStations(&CWinLogon::EnumWindowStationProc, NULL) ) // Note: CWinLogon::
home_window_station = 0;

If it is not static you need to use lParam to provide a pointer to an CWinLogon object. Or (rather not recommended) you use a global variable.
it works like a charm!
thank you!
Topic archived. No new replies allowed.