Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consuming .NET dll in VB6 application

Tags:

c#

vb6

I wrote a dll in c#.net that calls another third party .NET dll within the application. This works fine when I tested it with a console application written in c#.NET as well using the code below:

 Assembly u = Assembly.LoadFrom(dllLocation);
 Type t = u.GetType("MyLIB.CLass");
 MethodInfo m = t.GetMethod("Method");
 object[] myparam = new object[1];
 myparam[0] = fileLocation;
 result = (string)m.Invoke(null, myparam);

Please note that some files are loaded within the location where the dll was initially loaded as well using:

  string path = Assembly.GetExecutingAssembly().Location;
  path = Path.GetDirectoryName(path);

But the issue is that when I tried to call it using VB6, I get an error that it cannot load the third party dll. Please help as I seem not to know what's going on.

like image 320
Jay Avatar asked Jan 15 '23 13:01

Jay


1 Answers

I would thought to give you more detail, in order .NET Assembly expose to COM

you need to generate the tbl - type library

using RegAsm /tlb: MyLIB.tlb MyLIB.dll

There are Guidelines to expose .NET Types to COM and make sure you cope with that. such as declare ComVisibleAttribute , require a public default constructor to be visible to COM , such are in

you can refer that in How to call a Visual Basic .NET or Visual Basic 2005 assembly from Visual Basic 6.0

like image 102
Turbot Avatar answered Jan 25 '23 14:01

Turbot