I have the following code:
typedef void * (__stdcall * call_generic)(...); typedef void * (__stdcall * call_push2)(unsigned long,unsigned long); void * pfunc; // assume pfunc is a valid pointer to external function // this is a logically correct way of calling, however this includes: // add esp, 8 // after the call, and that breaks my stack. ((call_generic)pfunc)(1,1); // however, if i use this call: ((call_push2)pfunc)(1,1); // this does not happen and code works properly.
The pain of tracking all the calls and counting the arguments manually (there are a lot of such calls ahead), I would prefer a macro or something like that, but with this error it is not possible.
Is there a solution? Is there any other way to create a type call_genericto perform such actions?
call_generic
I really don’t understand why this is exactly what “cleanup” does, but it greatly destroys my stack, as a result of which previously defined variables are lost.
((call_generic)pfunc)(1,1); - , , pfunc, , , void *(...). varargs, varargs. varargs , varargs, ( , , ).
((call_generic)pfunc)(1,1);
pfunc
void *(...)
. - , , , .
, , , pfunc , . , varargs, . , , - , , , unsigned long call_push2.
unsigned long
call_push2
call_generic , __stdcall. , __stdcall , , OTOH (, ...) , .
__stdcall
...
, __stdcall - .
. , , .
. :
// any __stdcall function returning void taking 2 arguments template <typename T1, typename T2> struct FuncCaller_2 { typedef void * (__stdcall * FN)(T1, T2); static void Call(PVOID pfn, T1 t1, T2 t2) { ((FN) pfn)(t1, t2); } }; // call your function FuncCaller_2<int, long>::Call(pfn, 12, 19);
(0, 1, 2, 3,...).
, "" - .
, , protoype, . , boost:: bind - boost - ( , , ).