It doesn't seem the Data.Files object in OLEDragDrop supports Unicode.. it doesn't even return it, so can't send it for a conversion. I passed it straight to a Unicode messagebox to make sure (MessageBoxW StrPtr(Data.Files(0))), and question marks.
There's a couple ways to proceed. Of course my favorite is updating your whole drag/drop method to the fancy new one with IDropTarget that shows file icons when you drag over, among other things.
But the least disruptive is to just drop in a technique to get the Unicode filenames by converting the DataObject into an IDataObject. You will need a typelib with IDataObject defined, such as any version of mine or the original olelib, or really any as long as it's got IDataObject... Any Windows version is fine; it will work on XP... after that:
You now have an array of the dropped filenames, in Unicode, in sFiles()Code:Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Private Declare Function DragQueryFileW Lib "shell32.dll" (ByVal hDrop As Long, ByVal iFile As Long, Optional ByVal lpszFile As Long, Optional ByVal cch As Long) As Long Private Declare Function SysReAllocStringLen Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long, Optional ByVal Length As Long) As Long Private Sub Form1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) If Data.GetFormat(vbCFFiles) Then Dim pDataObj As oleexp.IDataObject 'change to olelib.IDataObject if using that, or any other typelib used Dim fmt As FORMATETC Dim stg As STGMEDIUM Dim sFiles() As String Dim nFiles As Long Dim i As Long Dim sBuffer As String CopyMemory pDataObj, ByVal ObjPtr(Data) + 16&, 4& fmt.cfFormat = CF_HDROP fmt.TYMED = TYMED_HGLOBAL fmt.lIndex = -1 fmt.dwAspect = DVASPECT_CONTENT pDataObj.GetData fmt, stg nFiles = DragQueryFileW(stg.Data, &HFFFFFFFF, 0, 0) ReDim sFiles(nFiles - 1) For i = 0 To nFiles - 1 SysReAllocStringLen VarPtr(sBuffer), , DragQueryFileW(stg.Data, i) DragQueryFileW stg.Data, i, StrPtr(sBuffer), Len(sBuffer) + 1& sFiles(i) = sBuffer Next CopyMemory pDataObj, 0&, 4& 'Must be freed like this End If End Sub
Edit: PS- When you say you want to get text, do you mean like dragged text without files? Like how you can drag text out of Wordpad? If the origin supports dragging it, via CF_UNICODETEXT, you can retrieve it in VB using a variation of the above technique; if interested let me know.




Reply With Quote
