Search code examples
c++winapiwin32-process

c++ CALLBACK function type


I'm trying to create something like MsgProc in Win32. When they declare the MsgProc function they have the CALLBACK type before it. So, all I'm trying to is create my own messsage function that calls my function to process the messages. It is basically the same thing when messages getting sent and processed. My question is how can i create the Same process?. An example would be great.


Solution

  • Other than the classics function pointers and function objects you may be interested by the new C++0x lambdas.

    Here's 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! ";});
    }