0

I have a COM visible dll which works fine with VBA. I would like to be able to see the XML documentation in the VBA editor and VBA object browser, is this possible?

by XML Documentation I mean for example Summary, param and remarks.

''' <summary>
''' Method to add some string.
''' </summary>
''' <param name="aString">The text to add.</param>
''' <remarks>Some remarks go here.</remarks>
Public Sub SomeSub(ByVal aString As String)


End Sub

If it is not possible what are my options for giving a user who wants to use my dll in VBA information about the classes, methods and functions available? Is there something that Visual Studio offers here? (Thus I have added Visual Studio as a tag)

darbid
  • 2,545
  • 23
  • 55

1 Answers1

1

As Hans Passant says 'No. You have to use the [Description] attribute'. Just to expand and include information from the SO question Hans then referenced it seems the Description attribute has to be the vehicle for all the documentation about the method parameters because COM Interface Definition Language IDL does not support such granularity.

Don't worry it seems one can put plenty of text in the Description field.

enter image description here

UPDATE: Additional information some VB.NET sample code.

  1. Open Visual Studio with Administrator Rights (Admin required to register)
  2. Create a VB.NET Class Library
  3. Go to Project Properties
  4. On the build tab check the Register for Interop check box
  5. Change the code for the default class to be the following

    
    Imports System.ComponentModel
    
    

    Public Interface Interface1

    <Description("Interface Description - Here we can put method information as well as parameter information")>
    Function AddNumbers(ByVal X As Integer, ByVal Y As Integer)
    
    <Description("Interface Description - Attempt to put description on Name")>
    Property Name() As String
    

    End Interface

    'https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.comclassattribute(v=vs.110).aspx

    Public Class ComClass1 Implements Interface1 Dim sName As String

    ' These  GUIDs provide the COM identity for this class
    ' and its COM interfaces. You can generate
    ' these guids using guidgen.exe
    Public Const ClassId As String = "7666AC25-855F-4534-BC55-27BF09D49D46"
    Public Const InterfaceId As String = "54388137-8A76-491e-AA3A-853E23AC1217"
    Public Const EventsId As String = "EA329A13-16A0-478d-B41F-47583A761FF2"
    
    Public Sub New()
        MyBase.New()
    End Sub
    
    <Description("Here we can put method information as well as parameter information")>
    Function AddNumbers(ByVal X As Integer, ByVal Y As Integer) Implements Interface1.AddNumbers
        AddNumbers = X + Y
    End Function
    
    Property Name() As String Implements Interface1.Name
        <Description("Attempt to put description on Name")>
        Get
            Return sName
        End Get
        <Description("Attempt to put description on Name")>
        Set(ByVal Value As String)
            sName = Value
        End Set
    End Function
    

    End Class

Also add a new project item, an interface, and paste in this code

  1. After successful build open Excel, create a workbook

  2. In the VBA go Tools->References , navigate to the ClassLibrary and check

  3. Go to the Object Browser and find your ClassLibrary and your ComClass1.

  4. For the method AddNumbers you should now see the Description

enter image description here

  1. Also using Hans Passant's tip about using the Description attribute on both the getter and the setter of a property can be verified.

enter image description here

BUT YOU ARE RIGHT @DARBID, the object browser shows the Description attribute is missing from the Interface Name.

I can only suggest that you use the MIDL compiler to get your assembly's Interface Definition Language (IDL), amend this IDL to give the Description attribute and then recompile and invite your users to browse your amended type library. Here is what IDL looks like


  [
      odl,
      uuid(54388137-8A76-491E-AA3A-853E23AC1217),
      version(1.0),
      dual,
      oleautomation,
      custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "ClassLibrary4.ComClass1+_ComClass1")    

    ]
    interface _ComClass1 : IDispatch {
        [id(0x00000001), helpstring("Class Description Here we can put method information as well as parameter information")]
        HRESULT AddNumbers(
                        [in] long X, 
                        [in] long Y, 
                        [out, retval] VARIANT* pRetVal);
        [id(0x00000002), propget, helpstring("Class Description Attempt to put description on Name")]
        HRESULT Name([out, retval] BSTR* pRetVal);
        [id(0x00000002), propput, helpstring("Class Description Attempt to put description on Name")]
        HRESULT Name([in] BSTR pRetVal);
    };

You can view the IDL of any COM library on your computer with OLEView.exe which is part of the Windows SDK.

Or perhaps someone can find a way to put gets and sets into a VB interface. I don't program in VB.NET I do VBA and C#. Sorry, I'm out of ideas now.

S Meaden
  • 8,050
  • 3
  • 34
  • 65
  • How about properties in VB.NET? – darbid Jan 28 '17 at 02:04
  • VB.NET properties doable and verified. Updated answer with sample code. – S Meaden Jan 28 '17 at 17:25
  • Thank you alot for the really easy to follow example. I have fully written interfaces but I see that you have not used an interface but let the compiler do it for you. In my and Hans' comments above you will see that we are talking about the Interface. So I would have to delete all my interfaces for this right? – darbid Jan 29 '17 at 15:58
  • Wait, I like the separate interfaces and classes approach. I've never done that in VB.NET. Why don't you post some code? Or, have you put the Description attribute on the Class or the Interface or both? – S Meaden Jan 29 '17 at 16:08
  • Ah, that's really interesting. Now I see your problem – S Meaden Jan 29 '17 at 16:18
  • I can post some code if you like but you just add an interface to your class and I think move your InterfaceId up to the interface. I hope I am not stretching the friendship here in asking do I need an interface? I have done it all already including interfaces for events, but I not having Property descriptions is annoying for my users. – darbid Jan 29 '17 at 16:21
  • 1
    Wait, I have an idea. I confirm your problem and will amend my answer (it's detailed as much for me as for you). My idea is that you get you 1) Build your component 2) Get the IDL 3) Amend the IDL 4) Recompile amended IDL to type library 5) Invite client programmers to use Tools References against your new type library. – S Meaden Jan 29 '17 at 16:24
  • Thank you S for sticking with me and even amending you first answer. Really great help. – darbid Jan 31 '17 at 05:09