3
votes

I want to create a VS2010 c# class that can be used in a Vb6 project. I've done simple C# class below and ticked the "register for com interop" in the build properties. In the Vb6 project I can see a reference for ComTestC but when I run the vb6 code I get:

run-time error '429' ActiveX component can't create object

I'm I missing an obvious step to getting this Com object working?

Vb6 Code

Private Sub Command1_Click()

Dim foo As Object
Set foo = CreateObject("ComTestC.Numbers")

End Sub

C# Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ComTestC
{
    public class ComTestC
    {

        [Guid("8b8d1e17-fc8e-4316-afb7-394a5da56801")]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        public interface _Numbers
        {
            [DispId(1)]
            int GetDay();

        }

        [Guid("68d6c981-66dd-4731-93a0-2c39bd86495f")]
        [ClassInterface(ClassInterfaceType.None)]
        [ProgId("ComTestC.Numbers")]
        public class Numbers : _Numbers
        {
            public Numbers() { }

            public int GetDay()
            {
                return (DateTime.Today.Day);
            }

        }


    }
}
1
Did you run regsvr32?Mike Cheel
I have never done this before, but am sure that you need to set ComVisible(true) to expose the class to COMSriram Sakthivel
Project + Properties, Application tab, Assembly Information button, tick the "Make assembly COM-Visible" option. You're likely to get a compile error next, you have to run VS elevated so the class can be registered.Hans Passant
You code workes fine for me. As Hans Passant said, "Make assembly COM-Visible" option is neccessary ...Daniel Dušek
Thanks guys by default "Make assembly COM-Visible" was false I changes this to true and all is fine thankspaul rockerdale

1 Answers