C#, COM Objects, & Interop Services
by Shehrzad Qureshi

Listing One

'Declaration of the ActiveX control
Dim CppControl As Cpp_ActiveX.CSimpleActiveX
Private Sub btnAdd_Click()
    ' grab data from input text boxes
    Dim a, b As Integer
    a = CDbl(txtA.Text)
    b = CDbl(txtB.Text)
    txtResult.Text = CStr(CppControl.Add(a, b))
End Sub

Private Sub Form_Load()
' instantiate control
Set CppControl = New Cpp_ActiveX.CSimpleActiveX
End Sub

Listing Two

using System;
using System.Runtime.InteropServices; // for DispId & Guid attributes
namespace CSharp_ActiveX
{
    /// <summary>
    /// COM object Interface
    /// </summary>
    [Guid("3D6E75CD-C44F-46fd-9723-F833B366129F")]
    public interface ICSharp_ActiveX
    {
        [DispId(1)] double Add(double a, double b);
    }
    /// <summary>
    /// The object that implements the above COM interface
    /// </summary>
    [
    Guid("1DBB9AEB-9333-408f-925C-4DE11599DEEF"),
    ClassInterface(ClassInterfaceType.None)
    ]
    public class CSharp_ActiveX_Class : ICSharp_ActiveX
    {
        public double Add(double a, double b)
        {
            return a+b;
        }
    }
}





