简体   繁体   English

在 VB6 中创建一个 dll 以在 .Net 应用程序中使用

[英]Creating a dll in VB6 for use in a .Net application

I have run into a problem where I need to use an old API created in VB6 which requires a vba.collection to be used when referencing the API for something.我遇到了一个问题,我需要使用在 VB6 中创建的旧 API,它需要在引用 API 时使用 vba.collection。

I can't do this in my .net project as it fails when trying to convert visual.basic.collection to vba.collection.我无法在我的 .net 项目中执行此操作,因为它在尝试将 visual.basic.collection 转换为 vba.collection 时失败。

I have found a workaround but cannot create the vb6 dll as I do not have vb6 and I cannot get hold of a copy.我找到了一种解决方法,但无法创建 vb6 dll,因为我没有 vb6 并且无法获得副本。

Below are the steps I need to carry out in VB6, could anyone kindly help me to create this dll so I can complete my project?以下是我需要在 VB6 中执行的步骤,有人可以帮我创建这个 dll 以便我可以完成我的项目吗?

Many Thanks!非常感谢!

Create a Visual Basic 6.0 DLL that returns the collection创建一个返回集合的 Visual Basic 6.0 DLL

Create a Visual Basic 6.0 Microsoft ActiveX DLL project.创建一个 Visual Basic 6.0 Microsoft ActiveX DLL 项目。 By default, the Class1 class is created.默认情况下,创建 Class1 类。

Rename the project CollectionFactory, and then rename the class clsVBACollection.重命名项目 CollectionFactory,然后重命名类 clsVBACollection。

Add the following code to the clsVBACollection class.将以下代码添加到 clsVBACollection 类。

 ' This function creates a new object of the VBA collection.
Public Function CreateVBACollection() As Collection

   ' Define a variable of type Collection.
   Dim col As Collection

   ' Create a Collection object.
   Set col = New Collection

   ' Return the Collection object.
   Set CreateVBACollection = col
End Function

On the File menu, click Make CollectionFactory.dll.在文件菜单上,单击生成 CollectionFactory.dll。

我能够使用 VB6 在 MS 文章中创建 dll,这解决了我的问题,我希望这对将来的人有所帮助!

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

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