views:

472

answers:

3

I have an application that is written in C#

I want to display a list of COM components in a folder on the system with details about the component, initially the ProgID.

Is there a way of interrogating a component from my C# code to find out the details at runtime.

A: 

Hmm, maybe you have to use TypeLibConverter class and work with regular .net framework metadata.

See here

Alex Stankiewicz
A: 

If you have absolutely no other runtime details of the COM components inside the DLLs, you could read and parse the registry resource embedded in the DLL. It is what is used during registration to register the ProgID and CLSID.

If you do know some runtime details about the COM components (such as interfaces that the components implement), there may be a way to backtrack it through the registry. (Though I don't believe there is a way to do this without using the brute force method below.)

Then of course there is the brute force method of enumerating the specific trees in the registry and matching the paths of the DLLs in the server/handler entries.

Nathan
A: 

If you have access to some interfaces in that COM object - you can do something like this:

[DllImport("ole32.dll")]
        static extern int ProgIDFromCLSID([In] ref Guid clsid,
           [MarshalAs(UnmanagedType.LPWStr)] out string lplpszProgID);

        //...

            Type t = someInterface.GetType();
            Guid tmpGuid = t.GUID;
            string sProgID;
            ProgIDFromCLSID(ref tmpGuid, out sProgID);
Oleg