Я реализовал интерфейс IOleDropTarget и также использую интерфейс IDropTargetHelper для отображения системного значка перетаскиваемого файла.
Часть моего кода DragEnter выглядит следующим образом
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
Преобразование pDataObj в IDataObject работает для всех типов объектов, которые я могу перетаскивать, кроме вложения электронной почты Outlook.Письмо само по себе работает нормально, но не вложение.Ошибка: неверная структура FORMATETC (Исключение из HRESULT: 0x80040064 (DV_E_FORMATETC)
Где я могу понять, что я делаю неправильно? Какой код я должен показывать?
мой интерфейс IDataObject выглядитвот так
<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
и структура FORMATETC вот так
<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
ОБНОВЛЕНО ddHelper - это экземпляр моего класса, приведенного из интерфейса IDropTargetHelper.
Private ddHelper As IDropTargetHelper = CType(New DragDropHelper(), IDropTargetHelper)
класс и интерфейс выглядят так
<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
И ошибка выглядит следующим образом.