Add Return for COM Interop marshaling to Short in Vb.NET

3. February 2012 14:10 by Mrojas in   //  Tags: , , , , , , , ,   //   Comments (0)

In VB.NET if you want to make your interfaces available thru COM and make sure that its parameters are of a certain type you have to use the MarshalAs attribute. For the return type it is a little tricky because it has to be added after the As Keyword.


<ComVisible(True)> _
<InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface MyCOMInterface
	Function FooReturningShort(ByVal data As Integer, <MarshalAs(UnmanagedType.U2)> ByVal shortData As short) As <MarshalAsAttribute(UnmanagedType.U2)> Short
End Interface

How to add helpstring in tlb generate from VB.NET or C# class

25. January 2012 11:34 by Mrojas in   //  Tags: , , , , ,   //   Comments (0)

In IDL you can have a helpstring attribute that adds descriptions to your interfaces.
To be able to generated those helpstring tags in a VB.NET  class you should use the Description tag

For example see this example taken from:

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace ClassLibrary1 {
    [ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface IFoo {
        int property {

NOTE: remenber that in some cases you have to apply the description attribute to both get and set.


After some test, I found that there are some differences with the helpstring behaviour in VB.NET. For example the helpstring attribute is not generated for methods. More on C#/VB.NET Interop Differences