As we know, we could use GetProcAddress to get a function pointer from a DLL handle such as for method foo defined at a DLL:
int foo(long)
we could get the function pointer like this for foo function:
typedef int(* FOO_FUNC)(long)
FOO_FUNC pFooFunc = (FOO_FUNC) GetProcAddress(dllHandle, "foo")
However we are thinking if we could make it dynamic further, let’s say, I know that I have a list of input argument and their type which is correct for current method and I would like to call this method on a dll and then get a list of output argument (with their type as well)
//VARIANT would be able to hold different type of data with different type
std::vector<VARIANT> inputArguments;
std::string methodName = "foo"
void * pFunc = GetProcAddress(dllHandle, methodName.c_str())
std::vector<VARIANT> outputArguments;
callMethodDynamically(pFunc, inputArgument, &outputArguments)
Is it possible to implement the above callMethodDynamically at C/C++? The only way I could think of is that we would have to push the argument to stack and then call the pFunc. I guess then it would be assembly language. Is there any other ways here? We would have to handle different call convention here as well (stdcall, cdecl).
Write a wrapper function for each real function.
e.g.
You could probably write a series of wrapper functions for each function prototype and simplify usage with some macros.