Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling vb6 dlls from c#

Tags:

c#

interop

vb6

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
like image 889
asp developer Avatar asked Feb 13 '12 05:02

asp developer


2 Answers

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.

like image 73
MarkJ Avatar answered Nov 02 '22 15:11

MarkJ


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

like image 2
Nanhydrin Avatar answered Nov 02 '22 15:11

Nanhydrin