Microsoft KB Archive/184332

= FIX: UserControl in VB4 or VC++ 5.0 Container Causes IPF on Exit =

Article ID: 184332

Article Last Modified on 3/21/2005

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition

-



This article was previously published under Q184332



SYMPTOMS
An application compiled in Visual Basic 4.0 or Visual C++ 5.0 generates an "Invalid Page Fault in MSVBVM50.DLL" error when the application is closed.



CAUSE
This error can occur in the following situation:

 The Visual Basic 4.0 or Visual C++ 5.0 application contains a UserControl created in Visual Basic 5.0.

-and-

 The UserControl contains a Class that creates a reference to the UserControl.

-and-

 You are running Windows 95 or Windows 98.



RESOLUTION
To work around this problem, use the ObjPtr function in combination with the CopyMemory API call to create the UserControl reference in the Class Module. The steps to complete the workaround are listed in the MORE INFORMATION section of this article.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Windows 2000.



MORE INFORMATION
WARNING: One or more of the following functions are discussed in this article; VarPtr, VarPtrArray, VarPtrStringArray, StrPtr, ObjPtr. These functions are not supported by Microsoft Technical Support. They are not documented in the Visual Basic documentation and are provided in this Knowledge Base article "as is." Microsoft does not guarantee that they will be available in future releases of Visual Basic.

Steps to Reproduce Behavior  Start a new ActiveX Control project in Visual Basic 5.0.</li> Name the project "passcontrol."</li> Add a Class Module to the project.</li>  Add the following code to Class1: Private mycontrol As passcontrol.UserControl1

Friend Sub passSelf(obj As passcontrol.UserControl1) Set mycontrol = obj mycontrol.SayHello

End Sub

Private Sub Class_Terminate Set mycontrol = Nothing End Sub </li>  Add the following code to UserControl1: Private myclass As New passcontrol.Class1

Private Sub UserControl_Initialize myclass.passSelf Me     End Sub

Friend Sub SayHello MsgBox "Hello!" End Sub </li> On the File menu, click "Make Passcontrol.ocx" to build the control.</li> Create a new project in Visual Basic 4.0 (32-bit) or Visual C++ 5.0.</li> Add Passcontrol.ocx to your project's form.</li> Compile (or build) the Visual Basic or Visual C++ application.</li> Run the application on a computer running Windows 95, Windows 98, or Windows Me.</li> Exit the application. You should receive the error " caused an Invalid Page Fault in Module MSVBVM50.DLL."</li></ol>

WARNING: If you reproduce this problem, it is advisable to restart the computer you are testing on after you receive the error. Passcontrol.ocx is locked by the system, and any attempt to manipulate this file causes your computer to freeze.

Workaround

In the Class Module, substitute the following code: Private Declare Sub CopyMemory _ Lib "kernel32" Alias "RtlMoveMemory" _ (pDest As Any, _           pSrc As Any, _            ByVal ByteLen As Long)

Private mycontrol As passcontrol.UserControl1 Friend Sub passSelf(ByVal ptrobj As Long) CopyMemory mycontrol, ptrobj, 4 mycontrol.SayHello End Sub

Private Sub Class_Terminate Set mycontrol = Nothing End Sub In the UserControl, substitute the following code: Private myclass As New passcontrol.Class1 Private Sub UserControl_Initialize myclass.passSelf ObjPtr(Me) End Sub

Friend Sub SayHello MsgBox "Hello!" End Sub

Additional query words: VC++ C++ user control activex ocx

Keywords: kbbug kbfix kbcrt kbctrlcreate KB184332

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.