Home  | Source Code  | Tools  | Links  | Search  |  
¿Habla Español?
Source Code Sections
ASP.NET General Internet Windows Explorer Windows Forms Old VB6 Code
Info

Valid XHTML 1.0!

Valid CSS!

How to get the IDataObject interface from the VB DataObject class

VB stores a pointer to the IDataObject interface in the 4th Long from the object pointer. Copying that pointer to a IDataObject variable you can use it.
 
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, _
                             Button As Integer, Shift As Integer, _
                             X As Single, Y As Single)
Dim MyDataObject as IDataObject

    ' Get an uncounted reference to the IDataObject 
    MoveMemory MyDataObject, ByVal ObjPtr(Data) + 16, 4

    ' Use the IDataObject interface

    ' Release the IDataObject
    ' You can't use Set = Nothing because
    ' the reference is not counted
    MoveMemory MyDataObject, 0&, 4

End Sub

The DataObject class in Common Controls implements the IDataObject interface. To get it just asign the object to the IDataObject variable:
 
Private Sub ListView1_OLEDragDrop(Data As ComctlLib.DataObject, _
                                  Effect As Long, _
                                  Button As Integer, Shift As Integer, _
                                  x As Single, y As Single)
Dim MyDataObject As IDataObject

    Set MyDataObject = Data

End Sub