简体   繁体   中英

Calling vb6 dlls from c#

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, ie 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

假设show方法show在dll的导出表中,请尝试使用DllImportAttribute来调用show方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM