我需要动态创建一个函数,外部库可以使用
__cdecl
调用约定,然后将调用重定向到类上的方法,有效地充当
__thiscall
调用约定。
主要的想法是(
program1
)应该从外部应用程序接收函数指针(
program2
),将其打包为可以查询我们的对象(
程序1
)要知道
程序2
是否应该制作,然后将其传递给图书馆。
我对此类课程的标题应该是什么样子有一个模糊的概念
template <typename F, class C>
class this_call_wrapper
{
public:
// Creates a wrapper function that calls `operator()` on `object`
// `operator()` should take the same arguments as `F`
this_call_wrapper(const C* object);
// Deallocates memory used by this and the wrapper
~this_call_wrapper();
// Returns the pointer to the function wrapper
F* get_wrapper();
private:
C* object;
F* wrapper;
};
有没有提供类似功能的库?如果没有,我如何在C++中实现这一点?