tags:

views:

476

answers:

4

I have created a class in c# and made the com visible property is true. But, i could not see the its properties at visual basic 6.0. what could be a problem? please help me

+1  A: 

Does ComVisible apply properly? Do you see the class in VB6, can you create an instance of it?

What names did you use for the properties? Do they perhaps use special COM rules to make them invisible (i.e. do they start with an underscore)?

Konrad Rudolph
Yes, i had set comvisble property as true and i able to create the instance for that class. but, i could not see the properties in vb
Sarathi1904
When you run it, do you see the objects in it while debugging with the visualizer?
Shimmy
You have to do more than that. At the very least you will have to define an interface that is visible to COM that your class will implement.
Ed Swangren
Not if you use [ClassInterface( ClassInterfaceType.AutoDual )]. Not that that's a good thing..
Ant
+1  A: 

Do you apply ComVisible(true) to class?

iburlakov
how do i set ComVisible(true) to class? Actually I set true in assemblyinfo.cs
Sarathi1904
+3  A: 

Define a public interface that is also ComVisible, and have your class implement that.

Then use tlbexp.exe to generate a type libary from your C# assembly:

tlbexp ComServer.dll /out:ComServer.tlb

You need to add a reference to the type library from VB6, not the assembly. How does VB6 know where your assembly actually is then? Regasm is how. It is the equivalent of regsvr32 for .net assemblies.

regasm ComServer.dll
James L
+1  A: 

As long as you make your class ComVisible in Properties (of Visual Studio 2005 or 2008, or set the ComVisible attribute to True in the Assembly file), you should be able to see your class in VB6. To get intellisense you need to declare an interface, give it a GUID, and implement it as shown in the example code below (Note: you have to create your own unique GUID's for both the interface and the concrete class.

using System.Runtime.InteropServices;
using System.Drawing;

namespace example_namespace
{

    [Guid("1F436D05-1111-3340-8050-E70166C7FC86")]    
    public interface Circle_interface
    {

        [DispId(1)]
        int Radius
        {
            get;
            set;
        }

        [DispId(2)]
        int X
        {
            get;
            set;
        }

        [DispId(3)]
        int Y
        {
            get;
            set;
        }

    }


    [Guid("4EDA5D35-1111-4cd8-9EE8-C543163D4F75"),
        ProgId("example_namespace.Circle_interface"),
        ClassInterface(ClassInterfaceType.None)]
    public class Circle : Circle_interface
    {

        private int _radius;
        private Point _position;
        private bool _autoRedeye;

        public int Radius
        {
            get { return _radius; }
            set { _radius = value; }
        }


        public int X
        {
            get { return _position.X; }
            set { _position.X = value; }
        }


        public int Y
        {
            get { return _position.Y; }
            set { _position.Y = value; }
        }
    }


}
Kris Erickson