简体   繁体   English

你如何在 vb6 中将 C# COM interropt DLL 作为参数传递

[英]how do you pass a C# COM interropt DLL as param in vb6

I have a C# DLL that is being used as a class to contain a list of properties about a file.我有一个 C# DLL,它被用作一个类来包含关于文件的属性列表。
The C# DLL is COM visible, and is able to be declared and instantiated in VB6. C# DLL 是 COM 可见的,并且能够在 VB6 中声明和实例化。
Inside my vb6 function where I create the object..在我创建对象的 vb6 函数中..

Dim fileObj As New MyCSharpClass.FileProperties

I am immediately able to see all the different properties accessible to my C# FileProperties object.我立即能够看到我的 C# FileProperties 对象可访问的所有不同属性。
fileObj.(intellisense) shows me the dropdown list of anything available inside the object fileObj.(intellisense) 向我展示了对象内任何可用内容的下拉列表
But when I pass my object to a function..但是当我将对象传递给函数时..

GetProperties(fileObj)

When I am inside GetProperties当我在 GetProperties 中时

Public Function GetProperties(ByRef pfileObj As MyCSharpClass.FileProperties)

When I try to have intellisense show me what options are available to me..当我尝试让智能感知向我展示我可以使用的选项时..
it does now recognize pfileObj as a variable I can use, it will not show up in intellisense它现在确实将 pfileObj 识别为我可以使用的变量,它不会出现在智能感知中
If I try to manually type it out, once again intellisense will not show me any options.如果我尝试手动输入它,intellisense 将再次不会向我显示任何选项。

pfileObj.

Is there a special way to pass COM interropt objects around to functions they were not delcared in inside of VB6?有没有一种特殊的方法可以将 COM interropt 对象传递给它们没有在 VB6 内部声明的函数?
Is this simply not possible?这根本不可能吗?
I was trying to avoid creating functions that return strings, and then assign to the object properties one at a time.我试图避免创建返回字符串的函数,然后一次分配一个对象属性。

The reason is because you need to have .NET create a TypeLib file which you can then reference from VB6.原因是因为您需要让 .NET 创建一个 TypeLib 文件,然后您可以从 VB6 中引用该文件。 VB6 will use this to display intellisense as well as assist VB6 in how to invoke your C# object. VB6 将使用它来显示智能感知以及协助 VB6 如何调用您的 C# 对象。 You need to do the following items:你需要做以下几件事:

  1. Declare an interface in C# which will publicly expose the properties/methods that you want VB6 to access.在 C# 中声明一个接口,它将公开公开您希望 VB6 访问的属性/方法。
  2. Implement the interface in your C# object using the colon character after your class name.使用类名后的冒号字符在 C# 对象中实现接口。
  3. Create a strong name for your project using the Strong name command line utility.使用强名称命令行实用程序为您的项目创建强名称。 (You can do this in the project properties in Visual Studio .NET). (您可以在 Visual Studio .NET 的项目属性中执行此操作)。
  4. Use the command line utility regasm.exe to create the necessary TypeLib file.使用命令行实用程序 regasm.exe 创建必要的 TypeLib 文件。
  5. Use gacutil to add your newly created tlb file to the GAC.使用 gacutil 将新创建的 tlb 文件添加到 GAC。
  6. Create a reference to the newly create .tlb file from VB6 (Project > References).从 VB6(项目 > 引用)创建对新创建的 .tlb 文件的引用。

You can find the detailed instructions here: http://www.codeproject.com/Articles/3511/Exposing-NET-Components-to-COM .您可以在此处找到详细说明: http : //www.codeproject.com/Articles/3511/Exposing-NET-Components-to-COM The article may be old but for the most part it is still applicable to the modern versions of Visual Studio.这篇文章可能很旧,但在大多数情况下,它仍然适用于 Visual Studio 的现代版本。

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

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