I have implemented the IOleDropTarget interface and am also using the IDropTargetHelper interface to show the system icon of the file being dragged.
Part of my DragEnter code looks like this
Public Function OleDragEnter(<[In]> <MarshalAs(UnmanagedType.Interface)> pDataObj As Object, <[In]> <MarshalAs(UnmanagedType.U4)> grfKeyState As Integer, <[In]> <MarshalAs(UnmanagedType.U8)> pt As Long, <[In]> <Out> ByRef pdwEffect As Integer) As Integer Implements IOleDropTarget.OleDragEnter
Dim x As Integer = CInt(pt And &H7FFFFFFF)
Dim y As Integer = CInt((pt >> 32) And &H7FFFFFFF)
Dim winPT As Win32Point
winPT.x = CInt(pt And &H7FFFFFFF)
winPT.y = CInt((pt >> 32) And &H7FFFFFFF)
ddHelper.DragEnter(hwnd, CType(pDataObj, NativeMethods.IDataObject), winPT, 0)
End Function
The cast of the pDataObj to an IDataObject works for every kind of object I can drag except for an Outlook email attachment. An email itself works fine but not an attachment. The error is Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC)
Where do I start to work out what I am doing wrong? What code should I show?
my IDataObject interface looks like this
<ComImport, Guid("0000010E-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Interface IDataObject
<PreserveSig>
Function GetData(
<[In]> ByRef format As FORMATETC, <Out> ByRef medium As STGMEDIUM) As Integer
<PreserveSig>
Function GetDataHere(
<[In]> ByRef format As FORMATETC, ByRef medium As STGMEDIUM) As Integer
<PreserveSig>
Function QueryGetData(
<[In]> ByRef format As FORMATETC) As Integer
<PreserveSig>
Function GetCanonicalFormatEtc(
<[In]> ByRef formatIn As FORMATETC, <Out> ByRef formatOut As FORMATETC) As Integer
<PreserveSig>
Function SetData(
<[In]> ByRef formatIn As FORMATETC,
<[In]> ByRef medium As STGMEDIUM,
<MarshalAs(UnmanagedType.Bool)> ByVal release As Boolean) As Integer
<PreserveSig>
Function EnumFormatEtc(ByVal direction As ComTypes.DATADIR, <Out> ByRef ppenumFormatEtc As System.Runtime.InteropServices.ComTypes.IEnumFORMATETC) As Integer
<PreserveSig>
Function DAdvise(
<[In]> ByRef pFormatetc As FORMATETC, ByVal advf As ComTypes.ADVF, ByVal adviseSink As ComTypes.IAdviseSink, <Out> ByRef connection As Integer) As Integer
<PreserveSig>
Function DUnadvise(ByVal connection As Integer) As Integer
<PreserveSig>
Function EnumDAdvise(<Out> ByRef enumAdvise As ComTypes.IEnumSTATDATA) As Integer
End Interface
and FORMATETC structure like this
<StructLayout(LayoutKind.Sequential)>
Public NotInheritable Class FORMATETC
Public cfFormat As UShort
Public dummy As Short
Public ptd As IntPtr
Public dwAspect As Integer
Public lindex As Integer
Public tymed As Integer
End Class
UPDATED ddHelper is an instance of my class cast from the IDropTargetHelper interface.
Private ddHelper As IDropTargetHelper = CType(New DragDropHelper(), IDropTargetHelper)
class and interface look like this
<StructLayout(LayoutKind.Sequential)>
Public Structure Win32Point
Public x As Integer
Public y As Integer
End Structure
<ComImport>
<Guid("4657278A-411B-11d2-839A-00C04FD918D0")>
Public Class DragDropHelper
End Class
<ComVisible(True)>
<ComImport>
<Guid("4657278B-411B-11D2-839A-00C04FD918D0")>
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Interface IDropTargetHelper
Sub DragEnter(
<[In]> ByVal hwndTarget As IntPtr,
<[In], MarshalAs(UnmanagedType.[Interface])> ByVal dataObject As NativeMethods.IDataObject,
<[In]> ByRef pt As Win32Point,
<[In]> ByVal effect As Integer)
Sub DragLeave()
Sub DragOver(
<[In]> ByRef pt As Win32Point,
<[In]> ByVal effect As Integer)
Sub Drop(
<[In], MarshalAs(UnmanagedType.[Interface])> ByVal dataObject As NativeMethods.IDataObject,
<[In]> ByRef pt As Win32Point,
<[In]> ByVal effect As Integer)
Sub Show(
<[In]> ByVal show As Boolean)
End Interface
User contributions licensed under CC BY-SA 3.0