I am working on a video project and I have a dll that receives video data coming in from the network.
I want to do the following.
1. Create a static global function in an existing class that will be used as a callback function.
2. Pass a pointer to this function to the dll that receives the video.
3. Whenever the dll receives video data, I want to call by global function defined in step 1 above.
I have access to the dll code so I can modify the function signature that creates it so it can receive a function pointer to my global function.
Can someone show me an example of how this is done??
void function(){
printf("This is the callback function.\n");
}
void DLLFunc(void(*callbackfunc)()){
// Check if recieves Video then
callbackfunc();
}
int main(){
DLLFunc(function);
return 0;
}
I think it's good form to typedef your function pointer.
It is also good practice to specify the calling convention, which is usually __stdcall for callbacks (windows.h defines CALLBACK accordingly).
1 2 3 4 5 6 7 8
typedefvoid(CALLBACK * PFNMYCALLBACK)(int,int);
void DLLFunc(PFNMYCALLBACK callbackfunc){
// Check if recieves Video then
int id = 1;
int length = 100;
callbackfunc(id, length);
}