Click here to Skip to main content
16,016,770 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: dynamically calling dll functions Pin
Ryan Binns30-May-05 17:55
Ryan Binns30-May-05 17:55 
GeneralRe: dynamically calling dll functions Pin
Tom Archer30-May-05 18:51
Tom Archer30-May-05 18:51 
GeneralRe: dynamically calling dll functions Pin
munawar196830-May-05 19:08
munawar196830-May-05 19:08 
GeneralRe: dynamically calling dll functions Pin
Cedric Moonen30-May-05 21:20
Cedric Moonen30-May-05 21:20 
GeneralRe: dynamically calling dll functions Pin
munawar196830-May-05 22:09
munawar196830-May-05 22:09 
GeneralRe: dynamically calling dll functions Pin
Tom Archer31-May-05 2:50
Tom Archer31-May-05 2:50 
GeneralRe: dynamically calling dll functions Pin
Tom Archer31-May-05 2:49
Tom Archer31-May-05 2:49 
GeneralRe: dynamically calling dll functions Pin
Ryan Binns30-May-05 22:46
Ryan Binns30-May-05 22:46 
Tom Archer  wrote:
The DLL name, function name and parameter and return info are all passed to me via XML elements.

Can you be certain they're correct? If the parameter info is wrong, then disaster could follow. Also, are you certain of what the calling convention is (C vs pascal etc.) as this affects how you should call it.

If you're sure it's safe, then the easiest way is probably to push the parameters on the stack in the right order and then call the method directly - some assembly required. It won't be very easy because you'll have to make sure that any intermediate operations you do in between pushing parameters (such as loading the next value, checking its type etc...) don't modify the stack (or at least leave it in the same state it began in). The return value (if there is one) will always be held in the EAX register (for an 8-bit to 32-bit return value) or EDX:EAX for a 64-bit value. For structures, I believe the EAX register hold the address of the return structure, but I'm not certain.

The other option is to dynamically compile some code that does the same thing, but again you'll run into difficulties passing the parameters.

One way I've had success in passing arbitrary parameter lists in the past is to assemble a block of memory that looks like the stack should, and then allocate space on the stack and copy the memory into it just before you call the function - much easier than managing pushes at the right time.

It would be much easier if you could narrow down the types and number of parameters a bit.

Anyway, I hope that helps a bit.

Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

GeneralRe: dynamically calling dll functions Pin
Tom Archer31-May-05 2:52
Tom Archer31-May-05 2:52 
GeneralRe: dynamically calling dll functions Pin
Ryan Binns31-May-05 3:21
Ryan Binns31-May-05 3:21 
GeneralRe: dynamically calling dll functions Pin
Ryan Binns31-May-05 4:09
Ryan Binns31-May-05 4:09 
GeneralRe: dynamically calling dll functions Pin
Tom Archer1-Jun-05 1:32
Tom Archer1-Jun-05 1:32 
GeneralRe: dynamically calling dll functions Pin
munawar196831-May-05 18:43
munawar196831-May-05 18:43 
GeneralRe: dynamically calling dll functions Pin
Tom Archer1-Jun-05 1:31
Tom Archer1-Jun-05 1:31 
GeneralRe: dynamically calling dll functions Pin
geo_m31-May-05 20:01
geo_m31-May-05 20:01 
GeneralExe as child process Pin
Michael Klim30-May-05 10:42
Michael Klim30-May-05 10:42 
GeneralRe: Exe as child process Pin
Ravi Bhavnani30-May-05 15:45
professionalRavi Bhavnani30-May-05 15:45 
GeneralProgram executes automatically Pin
Identity Undisclosed30-May-05 9:27
Identity Undisclosed30-May-05 9:27 
GeneralRe: Program executes automatically Pin
Toni7830-May-05 10:41
Toni7830-May-05 10:41 
GeneralRe: Program executes automatically Pin
Identity Undisclosed30-May-05 10:57
Identity Undisclosed30-May-05 10:57 
GeneralRe: Program executes automatically Pin
Christian Graus30-May-05 14:06
protectorChristian Graus30-May-05 14:06 
GeneralRe: Program executes automatically Pin
Identity Undisclosed31-May-05 2:32
Identity Undisclosed31-May-05 2:32 
GeneralRe: Program executes automatically Pin
Toni7830-May-05 16:18
Toni7830-May-05 16:18 
GeneralRe: Program executes automatically Pin
Toni782-Jun-05 3:46
Toni782-Jun-05 3:46 
GeneralRe: Program executes automatically Pin
Tom Archer30-May-05 14:02
Tom Archer30-May-05 14:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.