Alan
Alan

Reputation:

How do I get the ProgID of a COM component from C#?

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.

Upvotes: 2

Views: 5862

Answers (3)

Oleg
Oleg

Reputation: 601

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);

Upvotes: 1

user208608
user208608

Reputation:

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.

Upvotes: 1

Aleksander Stankiewicz
Aleksander Stankiewicz

Reputation: 550

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

See here

Upvotes: 0

Related Questions