我有一个功能:
long __stdcall call_DLL(long n, byte s0, byte s1, long(__stdcall *CallBack)(long m, byte s0, byte s1)){
//trying to copy the address of CallBack to another pointer
long *x = &CallBack;
}
我收到错误:
a value of type "long(__stdcall *CallBack)(long m, byte s0, byte
s1)"cannot be used to initialize an entity of type "long *"
任何人都知道我该怎么做?
答案 0 :(得分:1)
如果确实想要保存回调以便以后使用它,你可以这样做:
long (* __stdcall x)(long, byte, byte) = CallBack;
或在C ++中,您也可以使用auto
来简化:
auto x = CallBack;
在任何一种情况下,请稍后再使用
long ret = x(n, s0, s1);
否则,如果您只想调用CallBack,请执行类似
的操作long x = CallBack(n, s0, s1);
答案 1 :(得分:0)
不是使用不兼容的long *
初始化函数指针,而是使用兼容类型对其进行初始化。 this answer for C language
long __stdcall call_DLL(long n, byte s0, byte s1,
long (__stdcall *CallBack)(long m, byte s0, byte s1)) {
// long *x = &CallBack;
long (__stdcall *x)(long, byte, byte) = CallBack;
// sample usage of `x`
return x(n, s0, s1);
}