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?
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.
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.
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;
Related
I have a .net .dll written in c# and not being used as a COM interop.I need to use this dll as a reference in vb6.I got an error while adding the refrence "Can't add a reference to the specified file"?
By using command promt for registering i got an error " The module was loaded but the entry-point DllRegisterServer was not found. Make sure that it is a valid DLL or OCX file and then try again."
You cannot directly do what you are asking. The only thing that VB6 can "register" is by definition a COM DLL.
If you are not able to modify the C# DLL to add COM interface elements, then alternatively you could write a wrapper in C# or VB (.net) which itself exposes a COM interface, and internally calls the original DLL.
I have a library in C#, which i have exposed through COM to an unmanaged application in C++. On one machine, everything seems to have gone well. The interface is visible, is exposed, and the application is able to view it successfully, and use its functions.
On another machine, however, the .NET COM InterOp DLL is simply not visible to the calling application, I cannot debug on that machine so it is not immediately clear where the error is. I get a COM exception which indicates that I failed to create the COM object.
The DLL is present in the GAC, and the class is also registered in the registry, with the same class GUID as I have specified for it.
I have tried moving the assembly to the local folder, but still no detection. The DLL is dependent on another assembly which is present with it in the same folder. Moreover, the object creation for the other DLL, is dynamic and so it should not affect the object creation for the first assembly.
I might be overlooking a simple, fundamental step, since COM is new to me.
What could be the possible reason?
how can we create CLSID for DLL using regasm.exe
Actaully i want to use a windows application on web, i found an article on that, im posting the link below
http://www.codeproject.com/Articles/14276/Using-Windows-Application-on-web
In the above article im facing issue near the 10th step where it states that:: "Now by using the "regasm.exe" create and place the CLSID of your dll in the registry the exe file which is in the location "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\ "."
im not sure how to create the CLSID for the dll?
A CLSID identifies a COM class object, not a DLL.
When you register your assembly using regasm, a CLSID will be registered for each ComVisible class in your assembly.
You can specify the CLSID you want by placing a Guid attribute on a class:
[GuidAttribute("12345678-9012-3456-7890-123456789abc")]
public sealed class MyComVisibleClass ...
or if you don't use this attribute it will be generated automatically.
If it's generated automatically, you can inspect the type library generated by regasm using "OLE Viewer" or similar.
By calling
regasm.exe /codebase /tlb whatever.dll
depending on your needs, /codebase or /tlb might not be needed (i.e. you can also try just regasm.exe whatever.dll).
A CLSID is a globally unique ID (=GUID). It has a fixed format (see the Answer from Joe) and is "random". You can create one with guidgen.exe. Many Editors and IDE's have functionality to create a GUID. With regasm you can register the GUID (=CLSID then) of your COM class object in windows.
Ok, this line of code:
XMLHTTP40 http = new XMLHTTP40();
Throws a System.Runtime.InteropServices.COMException and complains that:
Retrieving the COM class factory for component with CLSID {88D969C5-F192-11D4-A65F-0040963251E5} failed due to the following error: 80040154.
I have googled that and I guess the DLL needs to be registered because its a COM DLL. That's fine, but when I try to register it I get this error:
C:\some\directory\path\etc\Interop.MSXML2.dll was loaded, but the DllRegisterServer entry point was not found.This file can not be registered.
Apparently this is working on another guys box (he wrote the code, so yeah.. :P). This COM object does not show up in my list of available COM references so I just reference the DLL which is sitting in the bin\Debug directory of the project. When I add the reference to this DLL to my project, I get access to all of the symbols in VisualStudio. I'm wondering, is there something that I can install that would register the DLL and have it show up in my list of COM objects that I can reference? I installed what I thought was the MSXML 4.0 library but when I looked in the directory there wasn't anything in there.
Any ideas?
You need to actually have MSXML4 installed on your box for it to work. THe interop dll doesn't contain any runtime code it only helps .NET talk to MSXML4.
However why would you not use the System.Xml namespace instead of using a COM component?
You need to register (regsvr32) msxml4.dll, not the interop assembly. msxml4.dll is the COM server.
Is there a programmatic way in C# to determine whether a particular COM DLL has been installed? Or is this a matter of scanning the registry for the classId?
What I usually did (and would do, if I needed this again) is try to create an object instance of a class you know is in the COM library - either by ProgID or GUID - and checking for failure.
Try and create it, and handle the error if not.
Under Win32 CoCreateInstance will return REGDB_E_CLASSNOTREG if not installed (including, IIRC, if registered but the dll/exe implementing it is then deleted).
Under .NET the generated COM interop assembly will throw some error (need to check this, don't have convenient code to test for which exception type). Note. if the interop assembly is missing then that will be treated as missing assembly possibly leading to an application load error.