背景:
我需要对一个dll进行二次封装,其中有一个接口,里面的参数需要传回调函数。
需求:
这个回调函数,我需要开放出去,并且减少回调函数参数的个数
示例:
// 回调原型 VOID __stdcall ImageCallback(HWND hWnd, BSTR imgBase64, ULONG_PTR userdata); // 接口原型 void __stdcall Image(ImageCallback fImage, ULONG_PTR pImage); /* * a.h */ // 回调 typedef void(__stdcall* imgCallback)(BSTR imgBase64); // 接口 void __stdcall Test(imgCallback fun); /* * a.cpp */ imgCallback f = NULL; VOID __stdcall ImageCallbackTest(HWND hWnd, BSTR imgBase64, ULONG_PTR userdata) { f(imgBase64); } void __stdcall Test(imgCallback fun) { f = fun; Image(ImageCallbackTest, NULL); }
现在别人调用我的回调的时候,就只有一个参数了