|
-
Jan 17th, 2018, 03:18 PM
#1
Re: Question about classes in VB6
The VBObjPtr() is a different value when called against a regular class as well (say, Class1).
And, FYI, that's an excellent explanation.
Last edited by Elroy; Jan 17th, 2018 at 03:23 PM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 17th, 2018, 03:21 PM
#2
Re: Question about classes in VB6
 Originally Posted by Elroy
The VBObjPtr() is a different value when called against a regular class as well (say, Class1).
check your declaration of VBObjPtr(). it's querying for IUnknown. Change it to Form1/Class1 and be amazed.
FYI: your VBObjPtr() function is casting/QI'ing to IUnknown, which is a totally different interface vs Form1.
You need to understand interfaces and Basic COM to get why that makes a difference. But basically it's a different interface to the same object.
Different Interface usually means different VTable and different instance data.
Code:
Option Explicit
Private Declare Function GetMem4 Lib "msvbvm60" (Src As Any, Dst As Any) As Long
Private Declare Function VBObjPtr Lib "msvbvm60.dll" Alias "VarPtr" (ByVal pObj As IUnknown) As Long
Private Property Get DeRef(ByVal Address As Long) As Long
GetMem4 ByVal Address, DeRef
End Property
Private Property Let DeRef(ByVal Address As Long, ByVal Value As Long)
GetMem4 Value, ByVal Address
End Property
Private Sub Form_Load()
Dim c1 As Form1
Dim c2 As Form1
Set c1 = New Form1
Set c2 = New Form1
Debug.Print "----c1 ----"
Debug.Print VarPtr(c1), "Address Variable"
Debug.Print VBObjPtr(c1), "Address of Instance Data for IUnknown"
Debug.Print DeRef(VBObjPtr(c1)), "Address of VTable for IUnknown"
Debug.Print DeRef(DeRef(VBObjPtr(c1))), "Address of QueryInterface Code for IUnknown"
Debug.Print ObjPtr(c1), "Address of Instance Data for Form1"
Debug.Print DeRef(ObjPtr(c1)), "Address of Vtable for Form1"
Debug.Print DeRef(DeRef(ObjPtr(c1))), "Address of QueryInterface Code for Form1"
Debug.Print "----c2 ----"
Debug.Print VarPtr(c2), "Address Variable"
Debug.Print VBObjPtr(c2), "Address of Instance Data for IUnknown"
Debug.Print DeRef(VBObjPtr(c2)), "Address of VTable for IUnknown"
Debug.Print DeRef(DeRef(VBObjPtr(c2))), "Address of QueryInterface Code for IUnknown"
Debug.Print ObjPtr(c2), "Address of Instance Data for Form1"
Debug.Print DeRef(ObjPtr(c2)), "Address of Vtable for Form1"
Debug.Print DeRef(DeRef(ObjPtr(c2))), "Address of QueryInterface Code for Form1"
Unload Me
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|