C ++ Type of function CALLBACK

I am trying to create something like MsgProcin Win32. When they declare a function MsgProc, before that they are of type CALLBACK. So, all I am trying to do is create my own messsage function that calls my function to handle messages. This is basically the same when messages are sent and processed. My question is: how can I create the same process ?. An example would be great.

+3
source share
3 answers

In addition to function pointers and class function objects that may interest you in the new C ++ 0x iamba.

Here is an example of passing a lambda to a timer function.

#include <windows.h>
#include <iostream>
#include <functional>

void onInterval(DWORD interval, std::function<void ()> callback) {
  for (;;) {
    Sleep(interval);
    callback();
  }
}

int main() {
  onInterval(1000, []() {std::cout<<"Tick! ";});
}
+1
source

If you can use Boost, I would definitely give Boost.Signals a shot, they provide the functionality you are looking for in a clean and safe way ( Boost.Signals2 even in thread safe mode.)

0
source

Source: https://habr.com/ru/post/1777157/


All Articles