tags:

views:

769

answers:

2

I am trying to write a wrapper around a legacy COM object and install the wrapper into the GAC. The goal would be to automate the setup of specific configuration information the component requires, and make a common strongly typed interface for all of my applications to use.

My solution thus far is to keep an XML configuration file in the same directory as the original COM DLL, and load the configuration in the class constructor. Unfortunately, I have been unable to find the location of the registered COM dll...

How do I get the full file path of the COM dll referenced by a COM object interop dll?

+1  A: 

Presumably you could get the GuidAttribute or CoClassAttribute values from the interop DLL that map to the CLSID and IID values of your COM DLL. Then you can look up the appropriate DLL path in the registry.

Jeff Yates
reg path: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID \ {guid-here-xxxx-xxxxxxxx}
Cheeso
I guess this will not work for (MSI) advertiesed components -- it is thus a rather brittle solution.
Johannes Passing
I'm not sure it's brittle because of that - finding the path of something that isn't yet installed is very difficult in any scenario inside .NET.
Jeff Yates
+1  A: 

Once you've created an object from the respective COM server, its DLL must have been loaded. So you could use P/Invoke and call GetModuleHandle( "mycomserver.dll" ) -- that gives you the path of the DLL.

Johannes Passing