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<
Do you apply ComVisible(true)
to class?
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
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; }
}
}
}