Load DLL File and execute an exported function from that DLL at runtime

Discussion forum about all things Gupta, OpenText and the community.
SSRJMC
Saudi Arabia
Posts: 12
Joined: 08 May 2017, 12:27
Location: Jeddah,Saudi Arabia

Load DLL File and execute an exported function from that DLL at runtime

Post by SSRJMC » 12 Dec 2019, 10:08

Hello everybody,

Is there a way to dynamically load DLL File and execute an exported function from that DLL at runtime ?

Please Anyone share me a Sample Code if it's Possible...

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2912
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Load DLL File and execute an exported function from that DLL at runtime

Post by Dave Rabelink » 12 Dec 2019, 10:59

Interesting question.

First, it depends on what you mean by "Load DLL and execute function at runtime".

Scenario 1)
When you know the DLL and function at compile time, you can declare the dll and function in the External Functions section and call it.
In fact, TD will load the DLL at runtime at the moment you call a function from it.
You can declare the function using the exact name or using the ordinal number.

Scenario 2)
When you know the DLL and function at compile time (as in scenario 1) but you are not sure the DLL is present at runtime or you are not sure the function is present in the DLL:
You can check if the DLL is on the system and if the function is present in the DLL prior calling it.
See this article how to do this:

https://wiki.tdcommunity.net/index.php/ ... at_runtime


Scenario 3)
When you do not know the DLL name and functions at compile time and runtime. So you want to use it dynamically at runtime.
So, as can be seen in scenario 2, we can detect the presence of the DLL and function at runtime.
In the end you can get a pointer to the function in the DLL.

But there is no way we can call the function straight from TD. TD does not support calling function pointers.
IMHO in this case you need to create a c++ wrapper which does it for you, but it is still not really fully dynamic.

The issues for this are explained here:

https://www.codeproject.com/Articles/91 ... lection-in



So it really depends what you need. Which scenario?
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests