In C#, I have a class and its interface in my solution, and I want them to be COM visible.
I have:
created the interface and the class as following:
[InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("0D1ABB24-144E-4C88-A4A5-DC3ED0E61BEB")]
[ComVisible(true)]
public interface IMyInterface
{
// methods here
}
[ClassInterface(ClassInterfaceType.None), Guid("01AA5822-83D1-42C6-A578-C9A84AB836AA")]
[ComVisible(true)]
public class MyClass : IMyInterface
{
// implementation here
}
(note they are both COM visible)
generated a GUID and informed it in the Assembly Info:
[assembly: Guid("MY-GUID-HERE")]
Registered it with this command line:
c:\regasm.exe /tlb MyAssembly.Dll
Imported the Type Library in Delphi 7.
A unit is generated, but it does not contain the class and functions/procedures. Calling CoClass.Create
returned a "Class not registered" error.
Later I created a new solution with a class library, performing the same operations above, and the classes/methods where generated and I could access them.
Are there any tips about what I might have missed?
I found out the difference. One TLB class I wanted to export had some constructors in a region. When I expanded it, I saw there was no overloaded constructor without parameters. After adding a no-argument constructor, it was visible at Delphi and I could use it normally.