BUG: UserControl in VB4 or VC++ 5.0 Container Causes IPF on ExitID: Q184332
|
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.
This error can occur in the following situation:
-and-
-and-
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.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
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
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
Private myclass As New passcontrol.Class1
Private Sub UserControl_Initialize()
myclass.passSelf Me
End Sub
Friend Sub SayHello()
MsgBox "Hello!"
End Sub
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 : kbCRT kbCtrlCreate kbVBp kbVBp400bug kbVBp500bug kbVC500bug
Version : WINDOWS:4.0,5.0; winnt:5.0
Platform : WINDOWS winnt
Issue type : kbbug
Last Reviewed: June 10, 1999