هل يتم التعامل مع Visual Studio 6 Typelibs بشكل مختلف في Visual Studio 2008 تحت Vista و 7؟

StackOverflow https://stackoverflow.com/questions/4020592

  •  26-09-2019
  •  | 
  •  

سؤال

لقد كتبت DLL قياسي في Visual Studio 6 C ++. لقد كتبت أيضًا typelib للذهاب معه بحيث يمكن استخدامها مباشرة في VB6 بدلاً من DECLARE.

إنه يعمل بشكل جيد في VB6 ضمن Windows XP.

ما لا يعمل هو عندما أتناول DLL و TLB في Vista و Windows7. هناك سجلات .tlb بخير مع REGTLIB لكن الرمز الوحيد المرئي في Visual Studio 2008 هو Attribution ثابت.

تم العثور على التقنية التي أحاول محاكاة كيفية جعل C DLL أكثر سهولة إلى 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
هل كانت مفيدة؟

المحلول

المشكلة هنا هي أنك لم تغير فقط نظام التشغيل ، بل قمت أيضًا بتغيير أدوات التطوير الخاصة بك. يجب أن يعمل إذا قمت بتشغيل VB6 على Win7. لكن Visual Studio 2008 يدعم VB.NET ، أ جداً لغة مختلفة من VB6. إنه يدعم المكتبات "الحقيقية" فقط ، تلك التي تستخدمها COM.

يتطلب استدعاء دالة تم تصديرها من DLL استخدام Marshaller P/Invoke المدمج في .NET. تحقق من DllimportAttribute وبيان VB.NET DECLARE في مكتبة MSDN. يجب أن يشبه الإعلان عن هذه الوظيفة:

<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 ستكون نهجًا آخر.

نصائح أخرى

أي سبب تقوم بإنشاء typelib وليس فقط إعلان الوظائف في VB6؟ وضع

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

في الجزء العلوي من الوحدة النمطية يبدو أكثر بساطة.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top