Problem class as the callback function found

Recently doing a project to use AVerMedia video capture card, its need for secondary development sdk, get the frame for processing.

As requested, the callback function is a static function, their definition of the callback function, then stick around the demo code, compile, error! ! Static display function can not reference variables illegal.

Helpless, technical advice, saying "static function can only be called a static variable, but also want to call the static member function in the function inside, it must pointer to the object."

Like this: CMyDlg * pThis = (CMyDlg *) lUserData;

That certainly can not implement the functionality directly in the callback function to call other functions to achieve,

Foggy ah, no way, referring to demo, redefine the class within the callback function pointer, then call the class member functions, and then implemented within member functions.

Such internal callback function callback: CMyDlg * pThis = (CMyDlg *) lUserData;

        pThis-> ShowPIP; // ShowPIP main function is to achieve function

In other words, the callback function to call a member function to achieve the main function; this change, compiled by the! Run, rely on, flash back! !

Grope days, do not know how it happened, only Baidu, and this article has given himself a great inspiration, click open the link , if you try to directly use the C ++ member function as a callback function error occurs, you can not even compile by,

Indeed it is, thanks to authors.

Well, the callback function itself certainly is a static function, can not be changed, but the real body of the function function (ie handler ShowPIP calls within the callback function) can be defined as normal C functions, rather than the class member functions,

Further relevant variables will only be defined as a global variable in the source file. in this way:

void ShowPIP(DataType A, DataType B);//定义

void ShowPIP(DataType A, DataType B)

{

...

} // function body

// callback function body

BOOL WINAPI callback(*, *, ...)

{

    ShowPIP(A, B);  

    return TRUE;

}


Compile, that's right!

Operating normally!

Nice!!!

Summary: do not use member function callback function is called directly using ordinary C functions.



Released four original articles · won praise 1 · views 2042

Guess you like

Origin blog.csdn.net/NWPUXL0513/article/details/51209221