-1

I read an example of this in this thread

C++: Best way to get Window Handle of the only window from a process by process id, process handle and title name

However it gives me an error I do not understand.

    1   IntelliSense: argument of type "BOOL (__stdcall CProcess::*)(HWND handle, LPARAM lParam)" is incompatible with parameter of type "WNDENUMPROC"

Can someone help me with this?

Community
  • 1
  • 1
pnda
  • 135
  • 1
  • 1
  • 11
  • 1
    That's a pointer to a member function. You need to pass in a pointer to a standalone or class static procedure. – HerrJoebob Feb 27 '15 at 22:09
  • Possible duplicate of [How to get main window handle from process id?](http://stackoverflow.com/questions/1888863/how-to-get-main-window-handle-from-process-id) – Jason C Oct 29 '15 at 15:46

1 Answers1

3

You can't use a non-static member function as a C language callback, because the member function has a hidden this argument.

In Windows you can use a static member function, but note that that is not a portable solution.

The most portable and safest is a namespace scope function.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • Portability is very likely not a design goal, when passing a function pointer to [EnumWindows](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633497.aspx) (a Windows API call). – IInspectable Feb 28 '15 at 14:43
  • @IInspectable: You're right: no Windows compilers I know (admittedly very few now, but still) are fuzzy about this. I mentioned portability with regard to what conventions one adopts. It's a good idea to write system-portable code also for pure Windows programs, when that's possible, because the conventions and coding guidelines etc. transfer more easily, and because others may find it easier to understand / more familiar. – Cheers and hth. - Alf Feb 28 '15 at 15:42