简体   繁体   English

从.Net应用程序打开VB6表单时,内存无法“读取”错误

[英]The memory could not be “read” error when opening a VB6 form from a .Net application

I have an application written in C#.Net (Framework 2.0 if it matters). 我有一个用C#.Net(框架2.0,如果有关系)编写的应用程序。 It calls a VB6 exe that exposes a COM class with one method - that shows a form. 它调用一个VB6 exe,该exe用一种方法公开一个COM类-显示一种形式。

When the VB form is closed, I get a system error (Windows message): The memory location could not be read. 关闭VB窗体后,出现系统错误(Windows消息):无法读取内存位置。 Then, Windows asks me whether to close the application or debug it. 然后,Windows询问我是关闭应用程序还是调试它。 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. 在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. 此外,只有在我先单击“显示报告”按钮时,才会发生这种情况,该按钮将调用另一个COM DLL-Crystal报表-来生成报告。

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. VB在整个Main方法周围都有一个On Error Goto行,该行应捕获VB中的任何错误-但事实并非如此。 The error does, however, come from the VB-generated EXE file. 但是,该错误确实来自VB生成的EXE文件。

You could confirm which module within the VB exe is crashing by attaching an unmanaged debugger and seeing what the stack trace is. 您可以通过附加非托管调试器并查看堆栈跟踪是什么来确认VB exe中的哪个模块崩溃了。

Crystal Reports sounds like a likely culprit, but it is possible that something else is triggering the problem. Crystal Reports听起来可能是罪魁祸首,但可能是其他原因触发了该问题。 Assuming you have access to the VB code I would check that all the Crystal Report COM objects are being released correctly. 假设您有权访问VB代码,我将检查所有Crystal Report COM对象是否均已正确释放。 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. 如果您想要一个真正的黑客解决方案,则可以考虑在OnClose事件中调用Win32 TerminateProcess函数。 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). 这将终止该进程而不会通知任何附加的DLL ...不太漂亮,并且可能导致与数据库的悬挂连接,等等,这需要清理自身(可能是超时)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM