![](/img/trans.png)
[英]Application vanishes when trying to invoke an OLEDB provider with VB6 Form
[英]The memory could not be “read” error when opening a VB6 form from a .Net application
我有一个用C#.Net(框架2.0,如果有关系)编写的应用程序。 它调用一个VB6 exe,该exe用一种方法公开一个COM类-显示一种形式。
关闭VB窗体后,出现系统错误(Windows消息):无法读取内存位置。 然后,Windows询问我是关闭应用程序还是调试它。 我选择什么都没有关系,因为测试机上没有安装调试器,当我选择调试时,它会提示我必须关闭。
该错误仅在两种情况下发生(都必须适用):
基本上,流程是这样的:
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文件。
您可以通过附加非托管调试器并查看堆栈跟踪是什么来确认VB exe中的哪个模块崩溃了。
Crystal Reports听起来可能是罪魁祸首,但可能是其他原因触发了该问题。 假设您有权访问VB代码,我将检查所有Crystal Report COM对象是否均已正确释放。 如果遗留了某些东西,则可能与应用程序关闭发生严重的交互。
如果您想要一个真正的黑客解决方案,则可以考虑在OnClose事件中调用Win32 TerminateProcess函数。 这将终止该进程而不会通知任何附加的DLL ...不太漂亮,并且可能导致与数据库的悬挂连接,等等,这需要清理自身(可能是超时)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.