使用COM组件时出错
场景 - 我正在编写一个控制台应用程序。需要使用一个名为 Interop.ABCServer.DLL 的 DLL [我是 COM 新手,所以真的不知道它在哪里出现,但我已经通过 ILDASM 检查了这个 DLL,它打开并显示元数据。所以,我猜它是一个 .NET DLL,而不是 COM DLL]
现在,当我尝试通过从中启动某些类来使用它时,它给了我一个异常 - Retriving the COM class factory for component with CLSID<1111-第1111章……>由于以下错误而失败:80040154。
问题 - 假设 COM 组件是一项旧技术,需要先注册组件,我们需要以某种方式注册它。我如何注册这个组件(记住它是一个 .NET dll 而不是 COM dll)?
以上注册是否解决了问题?如果不是,那么如何解决。
现在我已经使用 regsvr32.dll 注册了 ABCServer.dll。 但是,
我有像
try
{
Ilookup LP = New LoopUpClass();
IServer Svr = LP.LookUpServer(hostname, port);
}
catch(Exception ex)
{
}
第 1 行这样的代码,之前出现错误,现在只是终止应用程序。 我什至在调试时在第 1 行和第 2 行添加了断点。但控制永远不会到达第 2 行,只要我在第 1 行按 F10,应用程序就会终止。
基本上,一旦我注册了 COM,我该如何使用它。我是否需要从“添加引用”对话框中的 COM 选项卡注册它,或者我是否需要重新创建 INTEROP.ABCServer.DLL 或者我可以使用我提供的原始 INTEROP.ABCServer.DLL。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的
Interop.ABCServer.DLL
似乎只是 运行时可调用包装器。它只包含编组对真实 COM 库的调用的代码。
因此,您需要第二个 dll,它是您的具体 COM 组件,您必须使用 regsvr32.exe 注册它。它可能称为 ABCServer.DLL
对于您附加的问题:
如果提供的互操作库是最新的,您可以使用它。如果没有,您可以使用 TLBMP.EXE 创建您自己的。当直接向 COM dll 添加引用时,CS 将为您动态生成 RCW 库。如果您要使用的多个 COM 库之间没有依赖关系,那绝对没问题。
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 calledABCServer.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.
80040154 通常是一个错误,因为 COM 组件尚未注册。您通常使用
regsvr32 yourdll.dll
注册COM dll,这会将GUID添加到您的注册表中,以便每当使用COM对象的GUID时,系统都会知道从哪里加载DLL。.NET 为 COM dll 创建一个包装器,这就是您看到的 Interop.*.* ,但是您需要注册该包装器所针对的 DLL。也许你在某处有一个 ABCServer.DLL。
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.Interop.ABCServer.dll 可能引用了其他一些包含 COM 代码的 dll。检查一下程序集清单,它们是什么。要注册 COM 组件,请使用 regsvr32。
如果您想检查某个组件是否已正确注册,请在注册表中的 HKEY_CLASSES_ROOT 下检查您的组件是否已正确列出。根据 CLSID,您可以在 HKEY_CLASSES_ROOT\CLSID 下查看以找出 dll 的路径。
Interop.ABCServer.dll probably references some other dll containing COM Code. Check in the assembly manifest which are they. To register a COM component, use regsvr32.
If you want to check that a component is wel registered, check in the registry under HKEY_CLASSES_ROOT that your component is well listed. Based on the CLSID, you can look under HKEY_CLASSES_ROOT\CLSID to figure out the path to the dll.