DOCUMENT:Q184332 23-APR-1998 [vbwin] TITLE :BUG: UserControl in VB4 or VC++ 5.0 Container Causes IPF on Exit PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:4.0,5.0; WINNT:5.0 OPER/SYS:WINDOWS winnt KEYWORDS: ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0 - Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0 - Microsoft Visual C++, 32-bit Editions, version 5.0 --------------------------------------------------------------------- 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. RESOLUTION ========== To workaround 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 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. MORE INFORMATION ================ Steps to Reproduce Behavior --------------------------- 1. Start a new ActiveX Control project in Visual Basic 5.0. 2. Name the project "passcontrol". 3. Add a Class Module to the project. 4. 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 5. 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 6. On the File menu, click "Make Passcontrol.ocx" to build the control. 7. Create a new project in Visual Basic 4.0 (32 bit) or Visual C++ 5.0. 8. Add Passcontrol.ocx to your project's form. 9. Compile (or build) the Visual Basic or Visual C++ application. 10. Run the application on a computer running Windows 95. 11. Exit the application. You should receive the error " caused an Invalid Page Fault in Module MSVBVM50.DLL." 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 ====================================================================== Version : WINDOWS:4.0,5.0; WINNT:5.0 Platform : WINDOWS winnt Issue type : kbbug ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1998.