0

我在 Visual Studio 6 C++ 中编写了一个标准 DLL。我还编写了一个 typelib 来配合它,以便它可以直接在 VB6 中使用,而不是通过 Declare。

它在 Windows XP 下的 VB6 中运行良好。

当我将 DLL 和 TLB 带入 Vista 和 Windows7 时,不起作用。.TLB 在那里可以很好地注册,REGTLIB但在 Visual Studio 2008 中唯一可见的符号是Attribution常量。

我试图模拟的技术可以在How To Make C DLL More Accessible to VB with a Type Library中找到。难道这种技术不再适用???

(缩写的)ODL 代码复制如下。知道发生了什么吗?

// This is the type library for BOBDE.dll
[
    // Use GUIDGEN.EXE to create the UUID that uniquely identifies
    // this library on the user's system. NOTE: This must be done!!
    uuid(EE090BD0-AB6C-454c-A3D7-44CA46B1289F),
    // This helpstring defines how the library will appear in the
    // References dialog of VB.
    helpstring("BOBDE TypeLib"),
    // Assume standard English locale.  
    lcid(0x0409),
    // Assign a version number to keep track of changes.
    version(1.0)
]
library BOBDE
{
    // Now define the module that will "declare" your C functions.
[helpstring("Functions in BOBDE.DLL"), version(1.0),dllname("BOBDE.dll")]   
    module BOBDEFunctions
    {
[helpstring("Blowfish Encode ASCII for ANSI"), entry("BEA_A")] 
    void __stdcall BEA_A( [in] BSTR p1, [in] BSTR p2, [out,retval] BSTR* res );
    // other very similar functions removed for the sake of brevity
const LPSTR Attribution = "This product includes cryptographic software written by Eric Young (eay@cryptsoft.com)"; 
    } // End of Module
}; // End of Library
4

2 回答 2

2

这里的问题是您不仅更改了操作系统,还更改了开发工具。如果您在 Win7 上运行 VB6,它应该仍然可以工作。但是 Visual Studio 2008 支持 VB.NET,这是一种与 VB6截然不同的语言。它只支持 COM 使用的“真正”类型库。

从 DLL 调用导出的函数需要使用 .NET 中内置的 P/Invoke 编组器。查看 MSDN 库中的 DllImportAttribute 和 VB.NET Declare 语句。该函数的声明应该类似于:

<DllImport("bobde.dll")> _
Function BEA_A( _
      <MarshalAs(UnmanagedType.BStr)> ByVal p1 As String, _
      <MarshalAs(UnmanagedType.BStr)> ByVal p2 As String) _
    As <MarshalAs(UnmanagedType.BStr)> String
End Function

无需为此注册类型库。用 C++/CLI 语言编写托管类包装器将是另一种方法。

于 2010-10-26T07:53:09.927 回答
0

您创建类型库而不只是在 VB6 中声明函数的任何原因?推杆

Private Declare Function BEA_A Lib "bobde.dll" _
(ByVal p1 As String, ByVal p2 As String) As String 

在您的模块顶部似乎要简单得多。

于 2010-10-26T14:59:16.360 回答