Question

I have an interface define in C#, for example:

[ComVisible(true), Guid("E37EBA3C-FB2E-4D4A-8A90-F6FAA99E85C9")]
public interface TestClass
{
    public void test_function();
}

I want to include this in a library define in IDL. I tried to achieve this by generating a .tlb from C# interface and include it with importlib. However, I do not see this interface in my library when I compile my idl file, but I see all of the other interfaces that I defined in this library through importing their idl files.

import "AnotherClass.idl"
library COMMONPROGRAMS{
    importLib(stdole32.tlb)
    importLib(stdole2.tlb)
    importLib(TestClass.tlb)

    interface TestClass;
    interface AnotherClass;
}

In summary, I want to know:

  • Is it possible to include a C# interface in a IDL library?
  • If so, how can I do this?

All answers are welcome. Thank you in advance for any answers submitted.

Was it helpful?

Solution

When you import a TLB with importlib you don't see the interfaces in the current TLB as they are not a part of that TLB. Those interfaces are already defined in TestClass type library, so they can't have another definition in the CommonPrograms library.

If you want to define the interface elsewhere but make it a part of your TLB, you need to import it with import TestClass.idl. One way to generate the IDL from TLB is to open the TLB in OLE/COM Object Viewer and choose File->Save As, then edit it. I suppose that this is not what you want, as most likely you want to have this procedure automated.

However, with importlib you can still reference TestClass interface from CommonPrograms types, so this is usually not a big obstacle, but that obviously depends on your requirements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top