Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kulik

void CallProc(char* name, ...)

This topic is 5225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
You declare a function pointer, and cast the result of GetProcAddress. Just check out MSDN for example code.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!