Link to home
Start Free TrialLog in
Avatar of bmutch
bmutch

asked on

Possible to pass object from vb.net program to vb6 executable?

Is there any way to pass an object from a vb.net program to a vb6 executable. I am currently passing some data in command line parameters to it, but I would like to pass in the whole "customer" object because I have made it an interop class and so the same class exists in the vb6 project. I could then just set the vb6 object equal to the passed in object from dotnet and be on my way.

thanks,
Bruce Mutch
Avatar of bmutch
bmutch

ASKER

Ok, I see that that was a stupid question. I have changed the VB6 program to a dll, added the .net classes that I need to pass to it as dll's in the vb6 program, and call the vb6 dll from the .net program, passing it the objects. The problem I have now it that a top level object is getting passed ok, wheras a child object inside that object is not making it into the vb6 program. Any ideas?

thanks.
Avatar of bmutch

ASKER

To explain further, I have a Customer object and a child ReportCollection object in dotnet that I can access fine. When I pass the Customer object to the vb6 dll, the child ReportCollection object is "Nothing": here is the code for the child object ReportCollection:

( do you think the problem is due to the "Inherits Hashtable". I had to use this so I could refer to the report objects in the ReportCollection by string keys)

<ComClass(ReportCollection.ClassId, ReportCollection.InterfaceId, ReportCollection.EventsId)> _
Public Class ReportCollection
    Inherits Hashtable

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class
    ' and its COM interfaces. If you change them, existing
    ' clients will no longer be able to access the class.

    Public Const ClassId As String = "22CB3A25-EE3F-41bb-8B20-FE6E414BA372"
    Public Const InterfaceId As String = "2B8026B3-7E25-4014-8AD5-6775A6C351D2"
    Public Const EventsId As String = "2BA1C216-DA58-4531-8211-DD02FBFB5D92"
#End Region
    'Inherits NameValueCollection
    'Inherits CollectionBase
    Public Sub New()
    End Sub

    Default Public ReadOnly Property GetItem(ByVal Index As Object) As Report
        Get
            Return CType(Me.Item(Index), Report)
        End Get
    End Property

    Public Sub AddReport(ByVal _Item As Report)
        Me.Add(_Item.Name, _Item)
    End Sub

End Class
Avatar of bmutch

ASKER

changed the collection class code and it works perfectly now.

<ComClass(ReportCollection.ClassId, ReportCollection.InterfaceId, ReportCollection.EventsId)> _
Public Class ReportCollection
    Private mCol As Collection

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class
    ' and its COM interfaces. If you change them, existing
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "BCECC526-BC69-415C-8F1A-2F1CBB1D0F50"
    Public Const InterfaceId As String = "5C76AB26-729D-4E32-8AC1-5A19E494ADCE"
    Public Const EventsId As String = "CB1884B0-9B7C-4049-BC10-034A0512A196"
#End Region

    ' A creatable COM class must have a Public Sub New()
    ' with no parameters, otherwise, the class will not be
    ' registered in the COM registry and cannot be created
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
        mCol = New Collection()
    End Sub

    Public Sub Add(ByVal oItem As Report, ByVal sKey As String)
        mCol.Add(oItem, sKey)
    End Sub

    Public Sub Remove(ByVal sKey As String)
        Try
            mCol.Remove(sKey)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Default Public ReadOnly Property Item(ByVal Index As String) As Report
        Get
            Return mCol(Index)
        End Get
    End Property

    Public Function GetEnumerator() As System.Collections.IEnumerator
        'return our internal collection's IEnumerator.
        'COM calls this function when the collection is enumerated using the For-Each syntax
        Return mCol.GetEnumerator
    End Function

End Class
ASKER CERTIFIED SOLUTION
Avatar of EE_AutoDeleter
EE_AutoDeleter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial