Memory could not be "read" when opening a VB6 form from a .Net application

I have an application written in C # .Net (Framework 2.0, if that matters). It calls VB6 exe, which provides a COM class with one method - which shows the form.

When the VB form is closed, I get a system error (Windows message): The memory location could not be read. Windows then asks if it needs to close the application or debug it. It doesn't really matter which I choose, since there are no debuggers installed on the test machine and when I choose debug it gives me a message that it should close.

The error only occurs under two conditions (both must apply):

  • When this is done under Windows 2000.
  • Also, this only happens if I first click the Show Report button, which invokes other COM DLL - Crystal reports - to generate the report.

Basically, the flow looks 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 might be causing this error? VB has a line On Error Goto

surrounding the entire Main method that should catch any error in VB, but it doesn't. However, the error comes from the EXE file generated by VB.

0


source to share


1 answer


You can confirm which module in the VB exe will fire by plugging in an unmanaged debugger and looking at what a stack trace is.

Crystal Reports sounds like the likely culprit, but it is possible that something else is causing the problem. Assuming you have access to the VB code, I would verify that all COM Crystal Report objects are released correctly. If something remains, then it may not interact well with disabling the application.



If you want a really hackish solution, you might consider calling the Win32 TerminateProcess function in the OnClose event. This will terminate the process without reporting any DLL files attached ... not very nice and could cause database connections to hang, etc., which would have to clean themselves up (probably on timeout).

+1


source







All Articles