Archived

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

Function pointers - Out of curiousity

This topic is 5129 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 get an array of function pointers of unknown type from a DLL? I wanted to make a function which would return the function pointer type back of all the functions in the DLL to the loading client app without having to know the function pointer format of each function. ie.. pass back an array of function names and their pointer types. Im thinking this is TOO generic, but I hate writing headers all day =P.

Share this post


Link to post
Share on other sites
How the heck would your client know how to call the functions then? Yes, there are ways to do such a thing, but it really isn't the most efficient way, and like I said, how would the client know how to call each function unless you supply the data to it?

It'd require working with void pointers, an argument list, and pushing values onto the stack by hand (based on a variable list that would be gotten outside of code... if you do it in code, you must know the way to call such a function... for example...

You're .dll file has a function void SetNumber(int n); You're client needs to use this function to set a number... which means, somewhere in your code you'd need:

SetNumber(10);

But, in order for that to even compile, you'd need to either define it as an int taking function, or cast it before use...

(((void*)(int))GenericFunc)(10);

There isn't really a good way to call a function if you don't know what params it takes, unless someone wants to call it manually (say some sort of command prompt input deal, or something similar), where they could get a list of functions and arguments, and manually type what kind of call to make. So, you'd see a list of funcs, with void SetNumber(); in there, and you'd manually enter SetNumber(15);, in which case, you'd have to have a void pointer to a function with the name SetNumber, push the arguments onto the stack manually, and call the function with a void (void) type (since you pushed the correct type variables (which you compare the input against the functions argument list), the function will pop them if you call it with no parameters). This, in effect, does what a function call normally does... pushes params to stack, jumps to functions address, function pops them back off to use, all without having to know which functions do/need what .

--- Edit ---
Typo

[edited by - Ready4Dis on November 30, 2003 12:34:50 AM]

Share this post


Link to post
Share on other sites
Was just curious.

Sounds like alot more trouble than it's worth .

Thanks.

I guess it would be a good idea to check out the source to some scripting engines which are able to bind with native functions if I wanted to do something like that.




[edited by - Maega on November 30, 2003 12:55:35 AM]

Share this post


Link to post
Share on other sites