Consumption of .NET dll in VB6 application

I wrote a dll in C # .net that calls another third-party .NET DLL in the application. This works great when I tested it using a console application written in C # .NET, also using the following code:

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 downloaded in the place where the dll was originally downloaded, using:

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

But the problem 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 do not seem to know what is going on.

+4
source share
2 answers

I would consider giving you more details so .NET Assembly exposes COM

you need to generate tbl - type library

using RegAsm /tlb: MyLIB.tlb MyLIB.dll

There are Recommendations for deriving .NET types in COM and making sure that you handle it. such as declaring a ComVisibleAttribute , require the public value constructor to be visible to COM, such as

you can refer to this in How to invoke the assembly of Visual Basic .NET or Visual Basic 2005 from Visual Basic 6.0

+4
source

You need to specify ComVisibleAttribute on the assembly in order to call it from VB6.

+3
source

Source: https://habr.com/ru/post/1434684/


All Articles