尝试使用 COM 组件
我有一个 COM 组件。我在 32 位 XP 机器上使用 regsvr32 注册了它。现在,当我尝试在控制台应用程序中实例化它的类时,应用程序就会终止,不会给出任何异常。有什么建议吗??
COM dll 是 ABCServer.dll。失败的代码,
try
{
ILookUp LP = new LookUp();
ABCServer Svr = LP.LookUpServer(hostname, port);
}
catch(Exception ex)
{
Console.WriteLine(ex.message);
}
Control 永远不会到达第 2 行,而在调试时,当我在第 1 行时单击 F10 时,应用程序只是终止
I have a COM component. I registered it using regsvr32 on my 32-bit XP machine. Now when i try to instantiate a class from it in my CONSOLE application, the application just terminates, without giving any exception. Any suggestion??
The COM dll is ABCServer.dll. The code that fails,
try
{
ILookUp LP = new LookUp();
ABCServer Svr = LP.LookUpServer(hostname, port);
}
catch(Exception ex)
{
Console.WriteLine(ex.message);
}
Control never reaches line 2, while debugging when i click F10 when being on line 1, the application just terminates
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
COM 代码可能出于某种原因调用 C/C++
abort()
(或者 COM DLL 实现语言中的任何等效项)。由于 COM 服务器是进程内的,因此会立即终止整个进程。请注意,C++ 异常不能穿过 COM 边界(它们必须通过
ISupportErrorInfo
显式“封送”)。如果 COM DLL 中引发了异常,但 COM DLL 实现代码未正确捕获和处理异常,则可能会导致调用abort()
。如果您有 COM DLL 的调试信息,则可以尝试启用非托管代码调试(从项目属性的“调试”选项卡,或通过“附加到进程”对话框中的“选择”按钮)并单步进入本机 COM 代码以尝试诊断根问题。
The COM code probably calls the C/C++
abort()
for some reason (or whatever the equivalent is in the COM DLL's implementation language). And since the COM server is in-process, that immediately kills the whole process.Note that C++ exceptions cannot pass through the COM boundary (they must be explicitly "marshaled" via
ISupportErrorInfo
). If an exception was raised in the COM DLL but was not properly caught and handled by the COM DLL implementation code, this might have causedabort()
to be called.If you have debug information for COM DLL, you can try enabling unmanaged code debugging (from Debug tab of project properties, or through "Select" button in the Attach to Process dialog) and stepping into the native COM code to try and diagnose the root problem.