I have a COM visible nested class that looks like below.
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("12341234-3EDA-4A6D-9E84-804DCC625BE2")]
public interface ITestA
{
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(ITestA))]
[Guid("922F3F5A-0B65-4B58-AB91-76822A4FAA00")]
public class TestA : ITestA
{
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("43211234-3EDA-4A6D-9E84-123DFC625BE2")]
public interface ITestB
{
string SayHello();
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(ITestB))]
[Guid("922F3F5A-0B65-4B58-AB91-76822A4FAA00")]
public class TestB : ITestB
{
public string SayHello()
{
return "Hello";
}
}
}
And I use VBScript to instantiate the TestB class like below.
Set objTestB = CreateObject("Application.TestA.TestB")
Wscript.Echo objTestB.SayHello()
This is giving an error "ActiveX component can't create object" while instantiation of the COM object.
Application.TestA.TestB, there should be a registry key namedApplication.TestA.TestBunderHKEY_CLASSES_ROOT. That key should have a subkey namedCLSIDwhose default value is a GUID associated with the class. Finally, there should be a key underHKEY_CLASSES_ROOT\CLSIDwhose name is this GUID.