Skip to main content
GameDev.net gamedev.net
🔒 Locked

void CallProc(char* name, ...)

Started by kulik Jun 6, 2004 at 3:52 AM 2 replies 450+ views
Original Post
kulik
kulik
Is it possible to make some kind of caller proc? I have run-time loaded library and I can get a procedure from it but what if I want to directly call it? Like: void CallProc(char* name, ...) { FARPROC proc = GetProcAddress(module, name); // Now I must somehow get amount of parameters in ... // and pass them to proc; proc(param1, param2); // Or whatever } I am asking : Is this possible? If it is, how?
Zipster
Zipster
You declare a function pointer, and cast the result of GetProcAddress. Just check out MSDN for example code.
Yohomyth
Yohomyth
I don't know of any exact way to do this but here's what I would do instead:

//inside the library:

//the regular function would be:
//void Func(short a, long b);
void Func(void *pvParams)
{
short a = *(pvParams + 0); //what the first param would be
long b = *(pvParams + sizeof(short)); //the second param
DoSomething();
}
//=====================================================

//the callproc in the app

void CallProc(char *name, void *pvParams)
{
void (*Func)(void*) = (void(*)(void*)) GetProcAddress(module, name);
Func(pvParams);
}
//=====================================================

//now to call the function...

struct { short a; long b; } FuncParams;
FuncParams.a = 100; //just an example value
FuncParams.b = 1000;
CallProc("Func", *FuncParams);


I hope this helps..

[edited by - yohomyth on June 6, 2004 5:30:27 AM]

[edited by - yohomyth on June 6, 2004 5:31:54 AM]
------------------------------------------------------------"Many combilations elizagerth. I hope you see my particles." - Senor Cardgage
bytecoder
bytecoder
As long as you don't need to access the parameters in CallProc, what you're trying to do is possible.
x86 assembly:

CallProc:

; pop the function pointer off the stack and into eax
pop eax

; now call it with the parameters passed in
call [eax]

; restore the stack
add esp, 4

If the function returns a value, you have to cast CallProc before you call it, like so:

typedef int (*CallProc)(void*, int);

int (*pointer)(int);

int return = ((CastTo)CallProc)(pointer, 10);

Some of that code might need a little persuading to compile, but it should work.





[edited by - bytecoder on June 6, 2004 4:43:19 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.