如何从 DLL 创建 class 的新实例?

How to create a new instance of a class from a DLL?

我正在将使用 VB6 编码的旧应用程序转换为 VB.NET

在我的旧应用程序中,我使用的是第三方 DLL 文件。我们称它为 ThirdParty.dll.

我对 ThirdParty.DLL 的用法之一与 VB6 中的用法类似:

Dim MyApi as new x.y 'referenced from the ThirdParty.dll
Dim vReturnCode as Long

vReturnCode = MyAPI.InitialiserCles(a, b, c, d, e) 'consider a,b,c,d,e variables declared and initiaited.

在旧应用程序中,这将 return 结果为 Long

现在,我需要在我的新 VB.NET 应用程序中使用相同的 ThirdParty.dll

我创建的是这样的:

Public Class ThirdPartyAPI
    Private Declare Function InitialiserCles Lib "ThirdPartyFolder\ThirdParty" (a As String, b As String, c As String, d As String, ByRef e As String) As Long

    Public Function InitializeKey(a As String, b As String, c As String, d As String, ByRef e As String) As Long
        Return InitialiserCles(a, b, c, d, e)

    End Function
End Class

现在,当我想使用它时,我是这样做的:

Dim MyApi as new ThirdPartyAPI
Dim result as MyApi.InitialiserCles(a,b,c,d,e) 'consider again variables are well declared/initiated.

我收到以下错误:

Can't find DLL entry point 'InitialiserCles' in DLL ThirdPartyFolder\ThirdParty

我猜这是因为我们实际上是从那个 DLL 创建一个新的 x.y 实例,然后调用函数 InitialiserCles(在旧应用程序 (VB6) 中)。我在 VB.NET 中没有做同样的事情。我错过了什么?

由于这是我第一次使用 COM DLL 和其他东西,这对我来说并不容易。感谢上面的评论我能够做到。

下一个对我有用的是:

由于 ThirdParty.DLL 是一个 COM DLL,我必须使用 regsvr32 命令注册它。 请注意,我必须使用位于 SysWOW64 中的文件才能正常工作。 显然是因为它是一个 32 位 DLL 文件。然后命令是:

regsvr32 "FullPath\ThirdParty"

在 运行 此命令成功后,从 visual studio 我能够从名为 ThirdParty 的 com 对象添加引用,然后我能够从该 DLL 创建 类 的实例.