Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specify and Load DLL at run-time

Status
Not open for further replies.

SimonSellick

Programmer
Nov 3, 2003
305
0
0
GB
Hi,

I want to specify a DLL at run time, then load it and call its methods. The DLL will have been built as a VB6 ActiveX DLL (history). I was planning to use the Platform Invoke service but the DLLImport("x.dll") directive seems to need the DLL to be known at compile time.

All the DLLs will offer the same methods and API, so there is no discovery involved, just late binding.

Does anyone know a way to achieve this?

Any help welcomed.
 
Sorry for the excessive delay - I had to abandon the dynamic load temporarily while I made the application live, but I have now come back to it.

I'm sorry, but I can't quite see how to use the tips in the article you ponted me at.

Meanwhile, I have tried to run a MS example which is meant to load an assembly and list its methods - and the example fails!

The example is at

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref10/html/T_System_Reflection_Assembly.htm

And I used the C# examples. The line
Code:
            Assembly a = Assembly.Load(args[0]);
fails with an exception indicating that the referenced file or a dependant cannot be found or cannot be loaded. I've set the project's working directory, ensured that both the files generated by the library class project (dll and pdb) are in it and even done a System.IO.File.Exists() on args[0], but still get the same problem.

It looks as though Assembly.Load is at least part of the way towards what I am trying to achieve, but I'm a bit stuck as to why the example is failing.

Does anyone have any ideas, please?
 
hi,

the thread i mentioned talks about different approaches - 3 approaches - on how to load a ActiveX COM DLL on .NET.

The first 2 suggestions requires you having to know beforehand either the CLSID or ProgID of the COM class you want to consume.

The third option requires building a .NET wrapper around the COM DLL, which is an assembly that you can then load via the Assembly.Load() method.

hth [wink]
 
I finally got back to this project. After a bit more research I settled on the .net wrapper option and all is well now - thanks for the link.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top