none
VB.NET DLL created to use un VBA excel generate GUID, ClassId, InterfaceId, EventsId RRS feed

  • Question

  • I have managed to create dll to use it in VBA Excel. I have managed this with great help by people on MSDN. Now I want to find out how to generate GUID, ClassId, InterfaceId, EventsId in correct way. I know that GUID is generated automatically if project in Visual Studio is COM visible. How to generate ClassId, InterfaceId, EventsId??

    Here is vb code of my dll:

    <ComClass(Residual_SGR.ClassId, Residual_SGR.InterfaceId, Residual_SGR.EventsId)> _
    Public Class Residual_SGR
    
    #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 = "21815572-07ac-48c7-bcba-d0de7db6eef6"
        Public Const InterfaceId As String = "80b70fc2-1036-47d7-af6a-e0c11dddc01c"
        Public Const EventsId As String = "c8d56ef0-0c5d-4ba4-bae2-3175b6956f5d"
    #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()
        End Sub
    
        Public Function SGR(VISW As Double, VISO As Double, FI As Double, PB As Double, T As Double, RSPB As Double, CW As Double, GAMAO As Double, PMIN As Double, SWEX As Double, EQSW As Double, AK As Double, PCM As Double) As Double
            Dim A, B, X, C As Double
    
            PB = PB * 14.22334
            T = T * 1.8 + 32.0
            RSPB = RSPB * 5.6145821
            GAMAO = 141.5 / GAMAO - 131.5
            PMIN = PMIN * 14.22334
            A = -758.0 + 0.86 * FI + 5.29 * CW - 0.0444 * CW ^ 2 - 77.2 * Math.Log(CW) - 0.0386 * RSPB
            B = A + 0.0000533 * RSPB ^ 2 + 4.06 * GAMAO - 0.057 * GAMAO ^ 2
            X = 0.000156 * (PB / PMIN) ^ 2
            C = B + X + 2.02 * Math.Log(PB / PMIN) + 0.0123 * PB - 0.00000369 * PB ^ 2
            SGR = C - 3.71 * T + 0.00643 * T ^ 2 + 253.0 * Math.Log(T)
            Return SGR
        End Function
    
        Sub Hello()
            MsgBox("Greetings from VBFuncs.dll")
        End Sub
    End Class

    Wednesday, June 13, 2018 7:44 PM

Answers

  • I have managed how to do that. 

    In Visual Studio create New Project select Visual Basic Projects, under Templates select Class Library (.NET Framework) and then OK , by default Class1.vb is created. On the Vuew menu select Solution Explorer. Right click Class1.vb and then click Delete. On the Project menu select Add New Item and from Templates select COM Class. All that you need are created. I have found this under :

    https://support.microsoft.com/en-us/help/817248/how-to-call-a-visual-basic-net-or-visual-basic-2005-assembly-from-visu

    here is code after all steps ready to use ( add your code after sub New):

    <ComClass(Mata.ClassId, Mata.InterfaceId, Mata.EventsId)> _
    Public Class Mata
    
    #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 = "96562eab-a6e3-4b13-bdb3-a7defd446067"
        Public Const InterfaceId As String = "61218a8d-ceda-4a85-9601-8b5c8193e7ea"
        Public Const EventsId As String = "029e3eb8-76ae-43f2-8f42-fcb6d8345642"
    #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()
        End Sub
    
    End Class

    • Marked as answer by Aleksandar_NS Wednesday, June 13, 2018 8:37 PM
    Wednesday, June 13, 2018 8:37 PM

All replies

  • I have managed how to do that. 

    In Visual Studio create New Project select Visual Basic Projects, under Templates select Class Library (.NET Framework) and then OK , by default Class1.vb is created. On the Vuew menu select Solution Explorer. Right click Class1.vb and then click Delete. On the Project menu select Add New Item and from Templates select COM Class. All that you need are created. I have found this under :

    https://support.microsoft.com/en-us/help/817248/how-to-call-a-visual-basic-net-or-visual-basic-2005-assembly-from-visu

    here is code after all steps ready to use ( add your code after sub New):

    <ComClass(Mata.ClassId, Mata.InterfaceId, Mata.EventsId)> _
    Public Class Mata
    
    #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 = "96562eab-a6e3-4b13-bdb3-a7defd446067"
        Public Const InterfaceId As String = "61218a8d-ceda-4a85-9601-8b5c8193e7ea"
        Public Const EventsId As String = "029e3eb8-76ae-43f2-8f42-fcb6d8345642"
    #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()
        End Sub
    
    End Class

    • Marked as answer by Aleksandar_NS Wednesday, June 13, 2018 8:37 PM
    Wednesday, June 13, 2018 8:37 PM
  • It worked exactly as I described in my answer to the last question you posted in the other thread about the sample VB.net solution that I provided to you. Didn't you see my answer?

    Wednesday, June 13, 2018 8:57 PM
  • Yes I have understand it and resolved what I need. Thank you very much!!
    Wednesday, June 13, 2018 9:14 PM