I have been trying to call a vb6 dll from a C sharp application, without using the registry. I want to use the path of the dll while using it. I am unable to create an object of the class of the vb dll. Please help! The code I have written so far is as follows:
Assembly assem = Assembly.LoadFile("dll path");
Type classType = assem.GetType("classname");
MethodInfo method = classType.GetMethod("show"); //My methos is called show
method.Invoke(null,null); // I have to invoke the method using class object, which I am unable to create
A VB6 DLL is a COM DLL. Usually you would register the DLL (in the registry) and then add a reference to the VB6 DLL from your .NET project.
This MSDN article gives a walkthrough of using registry-free COM from a .Net app.
Your VB6 dll as MarkJ mentions is a COM Dll, and they usually need to be registered using regsvr32 before you can use them.
Once it's registered you can add a reference to it the same as you would with a .NET dll, i.e. right click on References in the project, click Add Reference, then select the COM tab on the window and look for your COM Dll name.
Then you should be able to use it like a .NET reference.
Here is an example of how to use a COM reference to Microsoft Excel.
How to: Use COM Interop to Create an Excel Spreadsheet
If you specifically want late binding, then your dll still needs to be registered but you don't manually add a reference, you use Activator.CreateInstance() to get an instance of your COM object.
Calling COM component from C# using late binding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With