Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when using COM component

Scenario - I am writing a console application. Need to use a certain DLL called Interop.ABCServer.DLL [I'm new to COM, so really don't know where it comes into picture here, but i have checked this DLL through ILDASM, it opens and shows metadata. So, i guess it's a .NET DLL and not a COM DLL]

Now when i try to use it by initiating certain class from it, it gives me an exception - Retrieving the COM class factory for component with CLSID<1111-1111....> failed due to following error:80040154.

Questions - supposing COM component is an old technology and requires component to be registered first, we need to register it somehow. How do i register this component (remembering it's a .NET dll and not a COM dll)?

Is above registration the resolution of the problem? IF not, then how to resolve it.

Now i have registered ABCServer.dll using regsvr32.dll. But,

I have code like,

try
{
    Ilookup LP = New LoopUpClass();
    IServer Svr = LP.LookUpServer(hostname, port);
}
catch(Exception ex)
{

}

Line 1 that was giving error previously now just terminates the application. I'hv even added break points on line 1 and line 2 while debugging. But control never reaches line 2, application just terminates as soon as i press F10 while on line 1.

Basically, once i have registered the COM, how do i use it. Do i need to register it from COM tab in ADD REFERENCE dialog, OR do i need to create a INTEROP.ABCServer.DLL afresh OR can i use the original INTEROP.ABCServer.DLL that i was provided.

like image 332
EagerToLearn Avatar asked Feb 17 '26 13:02

EagerToLearn


2 Answers

Your Interop.ABCServer.DLL seems to be just the runtime callable wrapper. It contains just code that marshalls calls to the real COM library.

So you need a second dll which is your concrete COM component which you have to register with regsvr32.exe. Its probable called ABCServer.DLL

To your appended questions:

If the provided Interop lib is up to date you can use it. If not, you can create your own with TLBIMP.EXE. When adding a referecne to the COM dll directly, CS will generate the RCW lib on the fly for you. Thats absolutely ok, if you don't have dependencies between multiple COM libaries you want to use.

like image 160
Jan Avatar answered Feb 19 '26 03:02

Jan


The 80040154 is normally an error due to that a COM component hasn't been registered. You typically register a COM dll using regsvr32 yourdll.dll, this will add the GUIDs to your registry so that whenever the GUID for the COM object is used, the system will know where to load the DLL from.

.NET creates a wrapper for COM dlls and that is this Interop.*.* that you see however you need to register the DLL that the wrapper is for. Probably you have a ABCServer.DLL somewhere.

like image 33
AndersK Avatar answered Feb 19 '26 02:02

AndersK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!