无法“读取”内存 从 .Net 应用程序打开 VB6 表单时出错
我有一个用 C#.Net 编写的应用程序(框架 2.0,如果重要的话)。 它调用一个 VB6 exe,该 VB6 exe 通过一个方法公开 COM 类 - 显示一个表单。
当 VB 窗体关闭时,我收到系统错误(Windows 消息):无法读取内存位置。 然后,Windows 询问我是否关闭该应用程序或对其进行调试。 我选择什么并不重要,因为测试机器上没有安装调试器,当我选择调试时,它会给我一条消息,表明它必须关闭。
该错误仅在两种情况下发生(两者都必须适用): 在
- Windows 2000 下运行时。
- 此外,仅当我首先单击“显示报告”按钮时才会发生这种情况,该按钮调用另一个 COM DLL - Crystal reports - 生成报告。
基本上,流程是这样的:
C#.Net application |-- MDI Form | When clicking a button on the form, the VB6 method is called +-- showing the form. setParent(VBForm.Handle, DotNetForm.Handle) is called | and the form is shown. The called method returns (there is no return value) | | | +-- When clicking "Display report", crystal reports is used to generate a report and show it to the user | | | \-- When Exit button is clicked, form is closed - this is where the error occures | \-- .Net form keeps on living long after that inner form is closed
有谁知道什么会导致这样的错误? VB 有一个围绕整个 Main 方法的 On Error Goto
行,该行应该捕获 VB 中的任何错误 - 但事实并非如此。 然而,该错误确实来自 VB 生成的 EXE 文件。
I have an application written in C#.Net (Framework 2.0 if it matters). It calls a VB6 exe that exposes a COM class with one method - that shows a form.
When the VB form is closed, I get a system error (Windows message): The memory location could not be read. Then, Windows asks me whether to close the application or debug it. It doesn't really matter what I choose since there are not debuggers installed on the test machine and when I select debug it gives me a message that it will have to close.
The error only happens under two conditions (both must apply):
- When this is run under Windows 2000.
- Also, this only happens if I click the "Display Report" button first, which calls another COM DLL - Crystal reports - to generate a report.
Basically, the flow is like this:
C#.Net application |-- MDI Form | When clicking a button on the form, the VB6 method is called +-- showing the form. setParent(VBForm.Handle, DotNetForm.Handle) is called | and the form is shown. The called method returns (there is no return value) | | | +-- When clicking "Display report", crystal reports is used to generate a report and show it to the user | | | \-- When Exit button is clicked, form is closed - this is where the error occures | \-- .Net form keeps on living long after that inner form is closed
Does anyone know what could cause such an error? The VB has an On Error Goto
line surrounding the entire Main method, which should catch any error in VB - but it doesn't. The error does, however, come from the VB-generated EXE file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过附加非托管调试器并查看堆栈跟踪来确认 VB exe 中的哪个模块正在崩溃。
Crystal Reports 听起来可能是罪魁祸首,但也有可能是其他原因引发了该问题。 假设您有权访问 VB 代码,我将检查所有 Crystal Report COM 对象是否已正确释放。 如果留下了什么东西,那么它可能会与应用程序关闭产生不良交互。
如果您想要一个真正黑客的解决方案,您可以考虑在 OnClose 事件中调用 Win32 TerminateProcess 函数。 这将终止进程而不通知任何附加的 DLL...不太漂亮,并且可能导致与数据库等的悬空连接,需要自行清理(可能在超时时)。
You could confirm which module within the VB exe is crashing by attaching an unmanaged debugger and seeing what the stack trace is.
Crystal Reports sounds like a likely culprit, but it is possible that something else is triggering the problem. Assuming you have access to the VB code I would check that all the Crystal Report COM objects are being released correctly. If something is being left around then it could be interacting badly with application shutdown.
If you want a really hackish solution you could consider calling the Win32 TerminateProcess function within the OnClose event. This will terminate the process without informing any attached DLLs ... not pretty and may lead to dangling connections to databases, etc that will need to clean themselves up (likely on timeout).