Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Dll references between VB6 and .NET  (Read 3409 times)

0 Members and 1 Guest are viewing this topic.

dbran

    Topic Starter


    Rookie
    • Experience: Experienced
    • OS: Windows 7
    Dll references between VB6 and .NET
    « on: March 15, 2012, 10:43:15 AM »
    OK, here's one...

    I have a VB6 ActiveX dll that references another COM dll.  Let's call it "MyDll".  The VB6 code looks like this:

    Code: [Select]

    Public Function ComToBytes(objName As String, obj As Object) As Byte()
        Dim PropBag As PropertyBag
        Set PropBag = New PropertyBag
           
        PropBag.WriteProperty objName, obj
        ComToBytes = PropBag.Contents
    End Function
       
    Public Function BytesToType1(objName As String, obj() As Byte) As Mydll.Type1
        Dim PropBag As PropertyBag
        Set PropBag = New PropertyBag
       
        PropBag.Contents = obj
        BytesToType1= PropBag.ReadProperty(objName)
    End Function

    Public Function BytesToType2(objName As String, obj() As Byte) As MyDll.Type2
        Dim PropBag As PropertyBag
        Set PropBag = New PropertyBag
       
        PropBag.Contents = obj
        BytesToType2= PropBag.ReadProperty(objName)
    End Function


    Originally, I tried having only two methods in the class with one of them returning an Object type.  Then I could cast it respectively in .Net.  However, this was throwing an error - 'Object variable or With block variable not set'.  I believe this was because it didn't really know what it was returning.

    The .Net code references MyDll as well.  However, when it references the dll it Interops it.  So a call similar to:

    Code: [Select]

    Type1 myObj = serializer.BytesToType1(ref objName, ref objArray);


    will cause two errors:

    • The type 'MyDll.Type1' is defined in an assembly that is not referenced. etc...
    • Cannot implicitly convert type 'MyDll.Type1' to 'MyDll.Type1[<PATH TO INTEROPPED DLL>\Interop.TAMMACInterfaces.dll]'

    Obviously, the two dll versions contain the same information.  I can't add the reference as suggested in error 1 because it would just wrap it again.  Any ideas on something like this?

    Thanks!