Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15772

verify COMObjectFromPtr object is valid

$
0
0
Hi all,
How to verify that an object is valid and has not been deleted.
Using this code to get and ObjPtr object.

https://www.vbforums.com/showthread....=1#post5161749
Code:

Private Declare Function vbaObjSetAddref Lib "MSVBVM60.DLL" _
                        Alias "__vbaObjSetAddref" ( _
                        ByRef dstObject As Any, _
                        ByRef srcObjPtr As Any) As Long
                       
Private Sub Form_Load()
    Dim frm As Form1
   
    Set frm = COMObjectFromPtr(ObjPtr(Me))
   
    frm.Circle (100, 100), 100
   
End Sub

' //
' // Get COM object from pointer
' //
Public Function COMObjectFromPtr( _
                ByVal ptr As Long) As IUnknown
    vbaObjSetAddref COMObjectFromPtr, ByVal ptr
End Function

If by some mistake I delete the object.
How to verify that the variable is not a valid object, the program does not close when using it.

Thanks

Viewing all articles
Browse latest Browse all 15772

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>