Create a VB6 dll using Visual Studio 2015?

I have a windowing application created in Visual Studio.

I am referring to the COM API and I am trying to run this

L_RESULT = Visualfiles.SystemScript("HIST-TEL", sampleVisualBasicColl, "") 

The second parameter should contain a collection, so I created this

    Dim sampleVisualBasicColl As New Microsoft.VisualBasic.Collection()

    Dim item1, item2, item3, item4 As String
    item1 = "Items"
    item2 = "In"
    item3 = "A"
    item4 = "Collection"
    sampleVisualBasicColl.Add(item1, "firstkey")
    sampleVisualBasicColl.Add(item2, "secondkey")
    sampleVisualBasicColl.Add(item3, "thirdkey")
    sampleVisualBasicColl.Add(item4, "fourthkey")

But the error I get is

Cannot pass an object of type "Microsoft.VisualBasic.Collection" to enter "VBA.Collection".

I found this article which I think will help - https://support.microsoft.com/en-gb/kb/323737

But how do I follow steps 1-4?

I have visual studio community 2015 and am not sure how to create this dll?

Thanks for any advice!

+4
source share
1 answer

coclass - , Microsoft . , , CLSID. , , , . , [noncreatable].

, , vba7.dll, Collection. KB VB6 . , , 18 - , VB6. MSDN Ebay.

, , KB. , , - Collection. COM .

:

Imports System.Runtime.InteropServices

Namespace VBA    
    <ComVisible(True), Guid("A4C46780-499F-101B-BB78-00AA00383CBB")>
    Public Interface _Collection
        <DispId(0)> Function Item(<[In]> ByRef Index As Object) As Object
        <DispId(1)> Sub Add(<[In]> ByRef Item As Object, ByRef Optional Key As Object = Nothing,
                        ByRef Optional Before As Object = Nothing,
                        ByRef Optional After As Object = Nothing)
        <DispId(2)> Function Count() As Integer
        <DispId(3)> Sub Remove(<[In]> ByRef Index As Object)
        <DispId(-4)> Function _NewEnum() As IEnumerator
    End Interface

    '' <ComVisible(True)>
    <ClassInterface(ClassInterfaceType.None), Guid("A4C4671C-499F-101B-BB78-00AA00383CBB")>
    Public Class Collection
        Implements _Collection
        Private impl As New Microsoft.VisualBasic.Collection

        Public Sub Add(ByRef Item As Object, ByRef Optional Key As Object = Nothing, ByRef Optional Before As Object = Nothing, ByRef Optional After As Object = Nothing) Implements _Collection.Add
            impl.Add(Item, CStr(Key), Before, After)
        End Sub

        Public Sub Remove(ByRef Index As Object) Implements _Collection.Remove
            If TypeOf Index Is String Then impl.Remove(CStr(Index)) Else impl.Remove(CInt(Index))
        End Sub

        Public Function Count() As Integer Implements _Collection.Count
            Return impl.Count
        End Function

        Public Function _NewEnum() As IEnumerator Implements _Collection._NewEnum
            Return impl.GetEnumerator()
        End Function

        Public Function Item(ByRef Index As Object) As Object Implements _Collection.Item
            Return impl(Index)
        End Function
    End Class
End Namespace

, Collection VBA.Collection, . , , .

+9

Source: https://habr.com/ru/post/1655536/


All Articles