Advanced Function Pointer?
Great, Thank you " IfYouSaySo"! :)
I am sorry I feel a little dumb, not realizing that C++ must hade such a method.
But here’s another “function pointer” related question, which may be more advanced, if that’s ok? Let’s say you have a function (in your own application) whose arguments are cstomable stored in variable arrays and the function name you don’t know. The only thing you have as a pointer of the function is a simple memory pointer/adress (no real function pointer) that points to a memory location where the function is stored during run-time. The following code example would demonstrate what I am trying to say.
Code:
// MEMPTR is a variable type pointing to a location in memory
struct FUNCSTRUCT { // Function calling structure
MEMPTR *FunctPtr; // Function pointer
int VarCount; // Number of Variables
MEMPTR *VarPtr[255]; // Varaible pointers
int VarSize[255]; // Varaible byte sizes
}
MEMPTR CallFunc(FUNCSTRUCT *FunctData); // The powerful function that does the call
int TheRealFunc(int Argument){ // Declare normal function
return Argument;
}
int main(){
FUNCSTRUCT FuncData; // Declare function type
int Value = 1; // Give a value to send as argument
FuncData.FunctPtr = TheRealFunc; // Point to normal function
FuncData.VarCount = 1; // Number of values to send as arguments
FuncData.VarPtr[0] = Value; // Point to the value
FuncData.VarSize[0] = 2; // Byte size of an integer value
return CallFunc(&FuncData); // Call the function
}
Is it possible to create such a function as “CallFunc” that could call a function, only knowing the custom arguments and a memory pointer/address? If so then how and how would the “MEMPTR” variable type look like? I presume that this question is a lot harder and I guess it includes some low-level knowledge. But is this possible and if it is then please explain how and demonstrate it in code please or could you point me to a tutorial on this :confused: