0

Visual Studio 6C++で標準のDLLを作成しました。また、Declareを介さずに、VB6で直接使用できるように、それに対応するtypelibを作成しました。

WindowsXPのVB6では正常に動作します。

DLLとTLBをVistaとWindows7に取り込むと、機能しなくなります。そこで.TLBは正常に登録されますが、VisualStudio2008REGTLIBで表示される唯一の記号はAttribution定数です。

私がエミュレートしようとしている手法は、タイプライブラリを使用してCDLLをVBにアクセスしやすくする方法にあります。この手法が適用されなくなったのは事実ですか?

(省略された)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は、 VB6とはまったく異なる言語であるVB.NETをサポートしています。COMが使用する「true」タイプのライブラリのみをサポートします。

DLLからエクスポートされた関数を呼び出すには、.NETに組み込まれているP/Invokeマーシャラーを使用する必要があります。MSDNライブラリのDllImportAttributeとVB.NETDeclareステートメントを確認してください。その関数の宣言は次のようになります。

<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で関数を宣言するだけでなく、typelibを作成している理由は何ですか?パッティング

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

モジュールの上部にあるのは、はるかに単純なようです。

于 2010-10-26T14:59:16.360 に答える