com

jawadh90

Member
Joined
Jun 19, 2003
Messages
18
Im writing a component/control in vb.net and I need to be able to make it work in Office programs as well as vb6.

I need to write an activex control in vb.net basically.

can anyone help me?

thankx
 
I suggest you take a look in the MSDN at the ComClassAttribute class and read about that, and check out some of the other related topics off of that. Its not as simple as simply choosing which method you want to use in compiling the DLL; you need to do some of it yourself.
 
Here is an example COM Class I whipped up. Note that it does not generate a true COM DLL. The DLL still uses .NET, but when Register for COM Interop is on, it generates a .tlb (TypeLib) for you to use in VB6. You add it to the project references just as if you were adding a DLL.
Code:
To flag a class library as being a COM library, follow these steps:
 1. Right click on the project in the solution explorer, and click "Properties"
 2. Click the "Configuration Properties" node in the tree at the side, and under that,
    click the "Build" item.
 3. Check the "Register for COM Interop" checkbox
 4. Click OK

<ComClass(SimpleMath.classGuid, SimpleMath.interfaceGuid, SimpleMath.eventGuid)> _
Public Class SimpleMath
    These GUIDs were generated using the "guidgen.exe" tool, found at this location:
    C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\guidgen.exe
    Public Const classGuid As String = "D0637236-F915-447a-9347-E11770C07466"
    Public Const eventGuid As String = "09725A16-9195-4d8c-A4B4-D5404A3A4CC7"
    Public Const interfaceGuid As String = "C1D08CEA-2286-4285-ABF4-3C1E642F7C33"

    Public Function Add(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
        Return num1 + num2
    End Function

    Public Function Subtract(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
        Return num1 - num2
    End Function

    Public Function Multiply(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
        Return num1 * num2
    End Function

    Public Function Divide(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
        Return num1 \ num2
    End Function

    Every COM class must have a parameterless constructor to register properly
    Public Sub New()
        MyBase.New()
    End Sub
End Class
Also note that you must use VB.NET for this, as C# does not have support for the creation of COM components. Also, you cannot use these COM components from within another .NET application.
 
Back
Top