简体   繁体   English

在VB6应用程序中使用.NET dll

[英]Consuming .NET dll in VB6 application

I wrote a dll in c#.net that calls another third party .NET dll within the application. 我在c#.net中写了一个dll,它在应用程序中调用另一个第三方.NET dll。 This works fine when I tested it with a console application written in c#.NET as well using the code below: 当我用c#.NET编写的控制台应用程序测试它时,这也很好,使用下面的代码:

 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: 请注意,有些文件是在最初加载dll的位置加载的,使用:

  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. 但问题是,当我尝试使用VB6调用它时,我收到一个错误,它无法加载第三方DLL。 Please help as I seem not to know what's going on. 请帮忙,因为我似乎不知道发生了什么。

I would thought to give you more detail, in order .NET Assembly expose to COM 我想给你更多的细节,以便.NET Assembly暴露给COM

you need to generate the tbl - type library 你需要生成tbl - type library

using RegAsm /tlb: MyLIB.tlb MyLIB.dll 使用RegAsm /tlb: MyLIB.tlb MyLIB.dll

There are Guidelines to expose .NET Types to COM and make sure you cope with that. 有一些指南可以向COM公开.NET类型,并确保您能够应对这种情况。 such as declare ComVisibleAttribute , require a public default constructor to be visible to COM , such are in 例如声明ComVisibleAttribute ,要求公共默认构造函数对COM可见,例如

you can refer that in How to call a Visual Basic .NET or Visual Basic 2005 assembly from Visual Basic 6.0 您可以在如何从Visual Basic 6.0中调用Visual Basic .NET或Visual Basic 2005程序集中引用它

您需要在程序集上指定ComVisibleAttribute才能从VB6调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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