FIX: Multiple CreateObject May Cause GP Fault in VBOA300.DLL (113438)



The information in this article applies to:

  • Microsoft Visual Basic Standard Edition for Windows 3.0

This article was previously published under Q113438

SYMPTOMS

A general protection (GP) fault may result when working with OLE objects in Visual Basic if you repeatedly create new OLE objects.

CAUSE

When OLE objects are created with Visual Basic and that OLE object is subsequently set to Nothing, a hidden instance of the OLE application is spawned and then orphaned. This uses up system resources and eventually either the machine will hang (stop responding to input) or a GP fault will occur in VBOA300.DLL at 0001:0D03.

WORKAROUND

When you create OLE objects. Be sure to close or quit the OLE object before setting the variable to Nothing. Please see the example at the end of this article.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem has been corrected in Visual Basic version 4.0.

MORE INFORMATION

Steps to Reproduce Problem

  1. Start a new project in Visual Basic. Form1 is created by default.
  2. Add a command button (Command1) to the form.
  3. Add the following code to the Command1_Click event:
       Sub Command1_Click ()
          Dim X As object
          Dim R As object
          Dim Iterations As Integer
    
          While True
             Iterations = Iterations + 1
             Debug.Print Iterations
             Set X = CreateObject("Excel.Sheet.5")
    
             ' Enter the following two lines as one, single line:
             Set R = X.Parent.Sheets(1).Range(X.Parent.Sheets(1).Cells(2, 2),
                X.Parent.Sheets(1).Cells(52, 2))
    
             Set R = Nothing
             Set X = Nothing
          Wend
       End Sub
    						
  4. Run the program.
When this code is run, the program will eventually produce a GP fault. Closing the WorkBook will not circumvent this problem. You must quit the application to avoid the GP fault.

Example Workaround

The following code will not produce a GP fault:
   Sub Command1_Click ()
      Dim X As object
      Dim R As object
      Dim Iterations As Integer

      While True
         Iterations = Iterations + 1
         Debug.Print Iterations
         Set X = CreateObject("Excel.Sheet.5")

         ' Enter the following two lines as one, single line:
         Set R = X.Parent.Sheets(1).Range(X.Parent.Sheets(1).Cells(2, 2),
            X.Parent.Sheets(1).Cells(52, 2))

         ' The next line quits the application for an Excel object
         X.Application.Quit
         Set R = Nothing
         Set X = Nothing
      Wend
   End Sub
				

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:kbbug KB113438