none
Build a .NET DLL and call it from VB6

    Question

  • Hi

    I want to create a VB.NET DLL with public functions that I can call from a VB6 project.

    Can anyone recommend any tutorials/reading matters on how to create the VB.NET DLL?

    I have looked so far at How to call a Visual Basic .NET or Visual Basic 2005 assembly from Visual Basic 6.0

    I'm particularly having trouble understanding concepts of generating GUIDs, signing assemblies with strong names, ClasId/IntefaceId/EventsId and how to register the assembly on the end user's workstation.

    Many thanks


    Thursday, June 14, 2012 8:51 PM

Answers

  • Hello, you might consider Interop Forms Toolkit library. The home page for the ToolKit discusses a good deal about forms but you can write DLL projects also. When writing code you must keep in mind what VB6 recognizes and what it does not. For instance, the following function comes from me experimenting with the toolkit. The code uses LINQ and returns a string array which VB6 understands.

    Public Function LINQ_Demo() As String()
        Dim Names As String() = New String() {"Bob", "Mary", "Jane", "Bob", "Joe", "Bill"}
        Return (From Name In Names Select Name Distinct Order By Name).ToArray
    End Function

    This is the code in the VB6 project

    Private Sub cmdLINQ_ArrayDemo_Click()
        Dim DotNetTest As New InteropUserControlLibrary1.InteropUserControl
        Dim Names() As String
        Names = DotNetTest.LINQ_Demo
         
        For Each s In Names
            Me.List1.AddItem s
        Next
    End Sub


    KSG

    • Marked as answer by bob132 Friday, June 29, 2012 8:59 PM
    Friday, June 15, 2012 1:58 PM
  • The GUIDs are required by COM in order to uniquely identify the interfaces of the component. They are entered into the Registry when the component is registered. You can generate these values using VS (Tools...Create GUID...Option 6). Do not use the GUIDs provided in the code example of the article.

    A strong name is only required if you are registering the component in the GAC (Global Assembly Cache) so that it can be shared amongst applications. It is essentially a global install.

    As is mentioned in the article you use the Regasm utility to register the component outside of the GAC. Use the /Codebase argument if the DLL if not located in a folder other than the bin folder of the application where it is used.

    If there is something specific that you don't understand, please post a follow-up question.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, June 15, 2012 1:19 PM

All replies

  • The GUIDs are required by COM in order to uniquely identify the interfaces of the component. They are entered into the Registry when the component is registered. You can generate these values using VS (Tools...Create GUID...Option 6). Do not use the GUIDs provided in the code example of the article.

    A strong name is only required if you are registering the component in the GAC (Global Assembly Cache) so that it can be shared amongst applications. It is essentially a global install.

    As is mentioned in the article you use the Regasm utility to register the component outside of the GAC. Use the /Codebase argument if the DLL if not located in a folder other than the bin folder of the application where it is used.

    If there is something specific that you don't understand, please post a follow-up question.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, June 15, 2012 1:19 PM
  • Hello, you might consider Interop Forms Toolkit library. The home page for the ToolKit discusses a good deal about forms but you can write DLL projects also. When writing code you must keep in mind what VB6 recognizes and what it does not. For instance, the following function comes from me experimenting with the toolkit. The code uses LINQ and returns a string array which VB6 understands.

    Public Function LINQ_Demo() As String()
        Dim Names As String() = New String() {"Bob", "Mary", "Jane", "Bob", "Joe", "Bill"}
        Return (From Name In Names Select Name Distinct Order By Name).ToArray
    End Function

    This is the code in the VB6 project

    Private Sub cmdLINQ_ArrayDemo_Click()
        Dim DotNetTest As New InteropUserControlLibrary1.InteropUserControl
        Dim Names() As String
        Names = DotNetTest.LINQ_Demo
         
        For Each s In Names
            Me.List1.AddItem s
        Next
    End Sub


    KSG

    • Marked as answer by bob132 Friday, June 29, 2012 8:59 PM
    Friday, June 15, 2012 1:58 PM
  • Be aware that vintage VB is off topic in this forum, 

    Look for that in

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/6a0719fe-14af-47f7-9f51-a8ea2b9c8d6b


    Success
    Cor

    Friday, June 15, 2012 2:36 PM
  • I was going to try Interop Forms Toolkit Library as I had exposure to this previously.

    Unfortunately I am unable to install it, as posted here.

    Friday, June 29, 2012 7:23 PM
  • Somehow, by a  lot of trial and error, I managed to get it installed.

    The errors persist but the templates appear to be there.

    The Add-In wasn't appearing in VS put I managed to get it appear by copying directly from C:\Program Files (x86)\Microsoft Visual Basic Power Packs\Interop Forms Toolkit 2.1\Setup\User\ to where VS stores AddIn


    Friday, June 29, 2012 9:06 PM