How to call a function dynamically from a DLL?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Manesh S
    New Member
    • Oct 2010
    • 1

    #1

    How to call a function dynamically from a DLL?

    Hi All,

    I have a scenario where a windows application tries to load a 3rd party DLL and call any functions defined in that DLL.

    How to call a function dynamically from a DLL

    There are certain restrictions implied to this implementation, which includes:

    1) Return values should be an int
    2) Only primitive datatypes can be used as function parameters.

    The 32-bit version of the application have this implemented with the help of inline-assemblies. Now I'm to porting this to 64-bit and have a restriction of using inline-assemblies.

    So I have a scenario where I need to re-write this implementation and having trouble in identifying the signature of the function and the type of the function parameters dynamically.

    Note: The existing logic is like this:

    - the requested function name to call is already passed along with the values
    - Loads any dll using loadLibrary()
    - Get the requested function name address using getProcAddress
    - Based on the count of function arguments, each argument is checked for its type and then is pushed into a custom Stack ( using Inline assemblies __asm)
    - Once all the function arguments are pushed, the function pointer address is called using Inline again (call address) and everything works fine.

    - now with my case, I'm able to push arguments in my own stack, but not how to pop it(because not sure about the type of the argument).

    If any one had done implementations similar to this, please share your knowledge. Ur reply will be highly appreciated.

    Also please let me know for any questions (i know my writing is messy )

    Thanks in Advance,
    Manesh S
Working...