how to pass void function pointer as parameter

88 Views Asked by At

I need to use the function SetEventCallback in 3rd party dll.

void  __stdcall SetEventCallback(void __stdcall callbackFunc(int val))

This function registers callbackFunc as callback function of some registered events. If an event occurs, callbackFunc is called and you could know which event is occured through parameter val.

I want to know how to use the function SetEventCallback.


I tried using it as follows.

  1. Import function in dll
extern "C" __declspec(dllimport) void  __stdcall SetEventCallback(void __stdcall callbackFunc(int val));
  1. Define callback function in my application
void __stdcall callbackInApp(int val) {

    if(val == 0) {
        // Do something with val
    }
    else {
        // Do something with val
    }  
}
  1. Call function SetEventCallback by passing the function pointer as parameter
int main(void) {
 
    SetEventCallback(callbackInApp);
}

Compilation is success but callbackInApp is never called. Please let me know how to fix it.

0

There are 0 best solutions below