How to read COM TypeLib with C # or C ++?

My company created several COM objects, and they successfully used them from .NET. But now our client wants to switch to Java. I thought it would be interesting to use JACOB or j-interop (I'm not sure which one) for some tasks, but the resulting code is pretty unmanageable. So I want to write a tool that can read TypeLib COM libraries, and then generate Java shell classes to remove all this unmanaged code.

I am new to the COM world, so I don’t know how to get information about the interfaces, methods and parameters that describe the COM object. I read about what TypeLib is called, but I don't know how to read it. How can I get information from him?

+4
source share
1 answer

The official API is available here: Type Description Interfaces .

You can use it directly from C ++, but I suggest you use .NET (C # in my example) with an additional tool that Microsoft wrote a long time ago (mine dated 1997) with the name TLBINF32.DLL. It is also a COM object, but it is Automation (VBScript, Javascript, VB / VBA) and is compatible with .NET.

TLBINF32.DLL googling ( , , : tlbinf32.dll , , .ZIP , , ""...). , 32- DLL, 32-, . 64- .

MSDN 2000 : COM- TypeLib, VB ( .NET), .NET-.

#, lib ( MSHTML.TLB):

class Program
{
    static void Main(string[] args)
    {
        TypeLibInfo tli = new TypeLibInfo();
        tli.ContainingFile = @"c:\windows\system32\mshtml.tlb";
        foreach (TypeInfo ti in tli.TypeInfos)
        {
            Console.WriteLine(ti.Name);
            // etc...
        }
    }
}
+5

Source: https://habr.com/ru/post/1538552/


All Articles