Microsoft KB Archive/187983

= BUG: IDE Crash with Compiled GlobalMultiUse =

Article ID: 187983

Article Last Modified on 1/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q187983



SYMPTOMS
If the Terminate event of a GlobalMultiUse class calls a procedure in another DLL, and if the same GlobalMultiUse class had previously called the same DLL, then you receive an error and the IDE may crash.

With Visual Basic 5.0, you may receive one of the following errors:

Exception: privileged instruction (0xc0000096), Address: 0x00186a3a

-or-

VB5 caused an invalid page fault (or general page fault)

With Visual Basic 6.0, the IDE does not crash, but you may receive the following error:

Run-time error '-2147418105 (80010007)':

Automation error

This error translates to:

"The callee (server [not server application]) is not available and

disappeared; all connections are invalid. The call may have executed."



CAUSE
This problem can occur when the ActiveX components are not shut down in the necessary order when your client application ends. For example, suppose your client application uses two ActiveX DLLs (DLL1 and DLL2). If the Terminate event of a class in DLL2 calls a procedure in DLL1, but DLL1 has been shut down before DLL2, you can experience this problem because the procedure in DLL1 is unavailable. The "Steps to Reproduce Behavior" section of this article demonstrates this scenario and shows how to work around the problem by controlling the order in which the two DLLs shut down.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Start a new ActiveX DLL project and name the project P_DLL1. Name its default module C_DLL1Globals and change its Instancing property to GlobalMultiUse.  Add the following code to C_DLL1Globals: Public Function DLL1_Function As String DLL1_Function = "Func1" End Function

 Add a second new ActiveX DLL project and name the project P_DLL2. Name its default module C_DLL2Globals and change it's Instancing property to GlobalMultiUse.  Add the following code to C_DLL2Globals: Public Sub DLL2_FunctionWhichCallsDLL1_Function Dim s As String s = DLL1_Function

End Sub

Public Property Get PublicObject As C_PublicObject Set PublicObject = M_Globals.PublicObject End Property

</li> Add a second Class Module to P_DLL2. Change the name to C_PublicObject and change its Instancing property to PublicNotCreatable.</li>  Add the following code to C_PublicObject: Private m_Something As Integer

Private Sub Class_Terminate Dim s As String s = DLL1_Function End Sub

Public Property Let Something(ByVal vData As Integer) m_Something = vData End Property

</li> Add a Standard Module to P_DLL2 and name it M_Globals.</li> To create a reference to P_DLL1, click References on the Project menu and check P_DLL1.</li>  Add the following code to M_Globals: Private m_PublicObject As C_PublicObject

Public Property Get PublicObject As C_PublicObject If m_PublicObject Is Nothing Then Set m_PublicObject = New C_PublicObject End If       Set PublicObject = m_PublicObject End Property

</li> Add a Standard EXE project, and name the project GroupExe.</li> Name the default form frmGroupExe, and add a CommandButton to it.</li>  Add the following code to frmGroupExe: Private Sub Command1_Click DLL2_FunctionWhichCallsDLL1_Function End Sub

Private Sub Form_Load PublicObject.Something = 1 End Sub

</li> Save the project files.</li> Compile P_DLL1.dll and remove the P_DLL1 project from the project group by choosing Remove Project from the File menu.</li> Compile P_DLL2.dll and remove the P_DLL2 project from the project group by choosing Remove Project from the File menu.</li> In GroupExe, create a reference to P_DLL2.</li> Save your work.

NOTE: The next step will crash the IDE and you may lose your work if you do not save it at this time.</li> Run GroupExe, click the CommandButton, and then exit GroupExe. Note that the IDE crashes with one of the errors mentioned previously.</li></ol>

This problem occurs during the shut down process. If you were to trace the order in which the classes in the two DLLs shut down, you would see the following order of events:

C_DLL2Globals Terminate

C_DLL1Globals Terminate

C_PublicObject Terminate

The problem occurs when the Terminate event of C_PublicObject tries to call the DLL1_Function, which is in the C_DLL1Globals object. Because the C_DLL1Globals object has closed, the DLL1_Function cannot be called.

To work around this problem, make sure the C_PublicObject Terminate event occurs while the C_DLL1Globals object is still available. To accomplish this task, put code in the Terminate event of C_DLL2Globals that causes the C_PublicObject to terminate. This will force the C_PublicObject Terminate event to fire before the C_DLL1Globals object is closed. Here's the code modifications for the workaround:

Put the following procedure in the M_Globals module of P_DLL2:

Public Sub ClosePublicObject Set m_PublicObject = Nothing End Sub

Next, add the following code to the C_DLL2Globals class:

Private Sub Class_Terminate ClosePublicObject End Sub

Now, when C_DLL2Globals terminates, the ClosePublicObject procedure is run that causes the C_PublicObject object to terminate. The new order of events during shutdown is:

C_DLL2Globals Terminate

C_PublicObject Terminate

C_DLL1Globals Terminate

<div class="references_section">