2

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.

2
  • This is giving an error "ActiveX component can't create object" while instantiation of the COM object. Commented Nov 19, 2013 at 8:41
  • 2
    You are trying to have two coclasses with the same CLSID. That ain't gonna fly. Once this is resolved, check whether and which ProgIDs for the two classes got registered. For a ProgID of, say, Application.TestA.TestB, there should be a registry key named Application.TestA.TestB under HKEY_CLASSES_ROOT. That key should have a subkey named CLSID whose default value is a GUID associated with the class. Finally, there should be a key under HKEY_CLASSES_ROOT\CLSID whose name is this GUID. Commented Nov 19, 2013 at 13:25

1 Answer 1

2

Registering the COM library creates Application.TestA+TestB as CLSID. To instantiate with CreateObject("Application.TestA.TestB") add attribute ProgID in the c# code.

[ProgId("Application.TestA.TestB") 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.