I'm implementing remote procedure calls in my networking library. I want the user to be able to register functions with any kind of signature, so I use a void* for this.
I receive a char array over the net that contains the serialized parameters of the function to be called. So if the function takes two ints, it will be a char array of length 8. I have a void* that points to a C function that is to be called with the received parameters. How do I copy the parameter list to the stack at the location where the C function expects the parameters?
The following kinda seems to work, but is obviously a bad solution:
This has some disadvantages:Code:struct LargeStruct { int a; int b; int c; int d; }; typedef void (*CFunc)(LargeStruct x); DLLFUNC void tst(int x, void* funcPtr) { CFunc myFunc = static_cast<CFunc>(funcPtr); LargeStruct x; x.a = 0; x.b = x; x.c = 0; x.d = 0; (*myFunc)(x); // calls the function pointed to by funcPtr with parameters (0, 0, x, 0); // I could copy my char array over the LargeStruct }
-There is a limit to how large (in bytes) a parameter list can be (sizeof(LargeStruct)).
-I always have to copy the maximum amount of bytes, and if the function has a shorter parameter list, I will be writing to unknown memory.
Thanks



LinkBack URL
About LinkBacks


