Lambda connection with winapi EnumWindows
-
BOOL CALLBACK Enum_Windows_Callback(HWND handle, LPARAM lParam) { } HWND Find_Main_Window(unsigned long process_id) { EnumWindows(Enum_Windows_Callback, (LPARAM)&data); return data.window_handle; }
I mean, is it possible to create the
Enum_Windows_Callback
inside of a lambda connection? -
No, you can't do that.
QObject::connect
function takes a QObject derived class instance as its first parameter. When that instance emits a signal a functor is called. That functor can be another QObject derived instance, a lambda or a class with () operator, but the first param has to be QObject, because it is the thing that emits a signal.You don't have objects at all in that code, just two functions, and even if you had, those are WinAPI functions. WinAPI knows nothing about existence of Qt and they certainly don't emit Qt signals, so there's nothing to connect that lambda to.
You can pass a lambda to
EnumWindows
if you wantEnumWindows([](HWND handle, LPARAM lParam){ return TRUE; }, (LPARAM)&data);
but that has nothing to do with Qt.
-
BOOL CALLBACK Enum_Windows_Callback(HWND handle, LPARAM lParam) { } HWND Find_Main_Window(unsigned long process_id) { EnumWindows(Enum_Windows_Callback, (LPARAM)&data); return data.window_handle; }
I mean, is it possible to create the
Enum_Windows_Callback
inside of a lambda connection?I'm not sure what you mean by a lambda connection. What is that? Do you mean you want to define a function inside a lambda expression? If that's the case then no, you can't nest functions in C++, otherwise what would be a signature of that function?
If it's in a class then you have
Class::method()
.
In a namespace it'sNamespace::function()
.
What would it be for a lambda???::function()
?Can you describe what you want to achieve in more detail or give a code example (even if it's the wrong syntax) of what you'd like to do?
-
I'm not sure what you mean by a lambda connection. What is that? Do you mean you want to define a function inside a lambda expression? If that's the case then no, you can't nest functions in C++, otherwise what would be a signature of that function?
If it's in a class then you have
Class::method()
.
In a namespace it'sNamespace::function()
.
What would it be for a lambda???::function()
?Can you describe what you want to achieve in more detail or give a code example (even if it's the wrong syntax) of what you'd like to do?
connect(<?>, <the callback necessary for the winapi EnumWindows>, [this] (HWND handle, LPARAM lParam) { //... });
something like this
-
No, you can't do that.
QObject::connect
function takes a QObject derived class instance as its first parameter. When that instance emits a signal a functor is called. That functor can be another QObject derived instance, a lambda or a class with () operator, but the first param has to be QObject, because it is the thing that emits a signal.You don't have objects at all in that code, just two functions, and even if you had, those are WinAPI functions. WinAPI knows nothing about existence of Qt and they certainly don't emit Qt signals, so there's nothing to connect that lambda to.
You can pass a lambda to
EnumWindows
if you wantEnumWindows([](HWND handle, LPARAM lParam){ return TRUE; }, (LPARAM)&data);
but that has nothing to do with Qt.