I am writing a C program to call a DLL, but the typelist and return value are unknown. I found a way to bypass this: by not casting to any function.
//todll.c
int test(int arg1, int arg2) {
return arg1 + arg2;
}
//caller.c
#include <windows.h>
int main() {
HMODULE module = LoadLibrary("test.dll"); //load the library into an HMODULE
FARPROC proc = GetProcAddress(module, "test"); //get the process
printf("%d", proc((void*) 9), ((void*) 10);
}
And this works. But the issue is that the users can enter different argument lengths. I store the length of the arguments in a variable called argc (type int), and the actual arguments in a variable argv (type void**). Now I want to pass the argv to the dll.
I know i can do something like
switch (argc) {
case 0:
return proc();
case 1:
return proc(argv[0]);
case 2:
return proc(argv[0], argv[1]);
case 3:
return proc(argv[0], argv[1], argv[2]);
//etc...
case 127:
return proc(argv[0], argv[1], argv[2], argv[3], argv[4], /* etc... */, argv[126]);
}
But I think that there should be a better way to accomplish this.