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?
Once you've created an object from the respective COM server, its DLL must have been loaded. Assuming that the underlying COM server is implemented in "mycomserver.dll", you could use P/Invoke and call GetModuleHandle( "mycomserver.dll" ) -- that gives you the path of the DLL.
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.
If you know the CLSID of the COM dll, you can check if there's a key with that CLSID on HKEY_CLASSES_ROOT\CLSID\{CLSID-of-your-COM-component}
or HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{CLSID-of-your-COM-component}
(Wow6432Node => 32-bit COM registered on a 64-bit machine)
If the key is there, it means that the COM component is registered. Then look at the default value inside the sub-key InprocServer32
e.g.
HKEY_CLASSES_ROOT\CLSID\{12345678-9012-3456-7890-123456789012}\InprocServer32
HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{12345678-9012-3456-7890-123456789012}\InprocServer32
If helps, here is a reference example of how to open these keys using C# (you'd just have to check for the value in InprocServer32
): How to check COM dll is registered or not with C#?
Just reflect the AddIn
class.
var t = typeof(ThisAddIn);
var path = t.Assembly.CodeBase;