dcsimg
Results 1 to 22 of 22
  1. #1

    Thread Starter
    Addicted Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Posts
    180

    Post ole drag drop and problem with unicode charachters or load image with unicode

    hi i set oledragmode of form to manual and then i draged attached file on form,and then i want load it like loadpicture but form can not known name of file.
    any way to can fix it, i want use in ole drag drop and load image or use in common dialog too.

    Code:
    Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    End Sub
    in this event data.files(1) return name like "C:\Users\barnameha\Desktop\type\d?.jpg"
    how can fix it?
    Attached Files Attached Files
    Last edited by Black_Storm; Feb 14th, 2018 at 02:03 AM.

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,178

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Hi Black_Storm,

    I'm not positive (as I didn't test for you), but it seems that LaVolpe's Clipboard/DataObject Extension Class might get you out of trouble. Possibly just "Attach" the passed DataObject to the class and then use its methods to get the files you're interested in.

    Good Luck,
    Elroy
    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. Please understand that Ive been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a VB6 random code folder that is overflowing. Ive been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3

    Thread Starter
    Addicted Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Posts
    180

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Quote Originally Posted by Elroy View Post
    Hi Black_Storm,

    I'm not positive (as I didn't test for you), but it seems that LaVolpe's Clipboard/DataObject Extension Class might get you out of trouble. Possibly just "Attach" the passed DataObject to the class and then use its methods to get the files you're interested in.

    Good Luck,
    Elroy
    hi thanks,but problem not solved yet,can help more?
    i used attached in #1 and another 2 images ( see in image result) but not worked.

    result :
    Name:  001.jpg
Views: 192
Size:  26.2 KB
    Last edited by Black_Storm; Feb 14th, 2018 at 12:57 PM.

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,178

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Hi Black_Storm,

    LaVolpe is around often. If he's so inclined, maybe he can help you with his class. Not having actually used it, I feel like I'm the wrong person to throw myself into this one.

    Best Of Luck,
    Elroy
    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. Please understand that Ive been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a VB6 random code folder that is overflowing. Ive been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,208

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Quote Originally Posted by Elroy View Post
    Hi Black_Storm,

    LaVolpe is around often. If he's so inclined, maybe he can help you with his class. Not having actually used it, I feel like I'm the wrong person to throw myself into this one.

    Best Of Luck,
    Elroy
    @Black_Storm. A VB message box is not going display unicode correctly. And if you are using VB functions for writing files, you are not going to create files with unicode characters. May want to consider using APIs for reading/writing those files instead.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,178

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Ahh, we're now talking about reading/writing a Unicode file from disk?

    Black_Storm, I believe LaVolpe is talking about reading the file entirely with API calls, and that's certainly a good alternative (relying on Windows to sort everything out for you).

    But, if we're just trying to read a relatively standard (and not hugely large) Unicode file, here are some procedures I occasionally use (no API at all).

    Code:
    
    Option Explicit
    
    Public Function bFileIsUnicode(sFileSpec As String) As Boolean
        Dim iFle As Long
        Dim i As Integer
        '
        iFle = FreeFile
        Open sFileSpec For Binary As iFle
        Get iFle, , i
        Close iFle
        bFileIsUnicode = (i = &HFEFF)
    End Function
    
    Public Sub SaveStringToUnicodeFile(sData As String, sFileSpec As String)
        ' These are typically .TXT files.  They can be read with notepad.
        Dim iFle As Long
        '
        iFle = FreeFile
        Open sFileSpec For Binary As iFle
        Put iFle, , &HFEFF ' This is the Unicode header to a text file.  First byte = FF, second byte = FE.
        Put iFle, , UnicodeByteArrayFromString(sData)
        Close iFle
    End Sub
    
    Public Function LoadStringFromUnicodeFile(sFileSpec As String) As String
        ' These are typically .TXT files.  They can be read with notepad.
        Dim iFle As Long
        Dim bb() As Byte
        Dim i As Integer
        '
        iFle = FreeFile
        Open sFileSpec For Binary As iFle
        Get iFle, , i
        If i <> &HFEFF Then ' Unicode file header.  First byte = FF, second byte = FE.
            Close iFle
            Exit Function ' It's not a valid Unicode file.
        End If
        ReDim bb(1 To LOF(iFle) - 2&)
        Get iFle, , bb
        Close iFle
        LoadStringFromUnicodeFile = bb ' This directly copies the byte array to the Unicode string (no conversion).
        ' Note: If you try to directly read the file as a string, VB6 will attempt to convert the string from ASCII to Unicode.
    End Function
    
    Public Function UnicodeByteArrayFromString(s As String) As Byte()
        ' This directly copies the Unicode string into the byte array, using two bytes per character (i.e., Unicode).
        UnicodeByteArrayFromString = s
    End Function
    
    
    
    You will need to be a bit careful though. I believe you may occasionally run across a Unicode (UCS-2) file that doesn't have the &HFEFF header on it. In those cases, my procedures won't work.

    Good Luck,
    Elroy
    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. Please understand that Ive been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a VB6 random code folder that is overflowing. Ive been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  7. #7
    Addicted Member
    Join Date
    Sep 2014
    Posts
    145

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    There seems to be a misunderstanding on Posting #1. As I see it, the loading failure is merely owing to a Unicode file name, i.e. if you change the file name to English, then the loading would be okay (assuming Black_Storm's VB drag/drop code is okay).

    The image file itself is perfectly okay, I have tested the JPG file in the ZIP (with an English name only, otherwise I would have a better test). I could drop the file to invoke a paint program, drop it to a blank MDI surface, to a Child form and to a PictureBox, all okay. From the letterings shown on the displayed image, the language that Black_Storm is talking about is Iranian -- my wild guess only.

    So, if Lavolpe can give Black_Storm some Unicode stuff to enable his code to recognize the file name, e.g. in

    mFileSpec = data.Files(1)

    then the problem can be resolved, I believe.

  8. #8
    Addicted Member
    Join Date
    Sep 2014
    Posts
    145

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Black_Storm,

    The JPG file in your ZIP is with an English name. You got the "?" problem because you were using a non-English file name? If the original file is with an Iranian file name (or whatever a non-English name), would you please ZIP and upload that original file?

    Brenker

  9. #9

    Thread Starter
    Addicted Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Posts
    180

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    i created a product for a company to work for open images and show in picturebox and show name it on a label or ....
    thic company have more than 1000 images like attached in #1,so i can no tell to them (please rename to english or ....) i want fix this problem without reanem to english.
    can u send a simple project to can drag attached image in #1 on form ( use ole drag) and and a button for use commonn dialog and can show in a picturebox and show name of file in a lable too?

    my porblem is about :
    1-i can not drag and drop or use commong dialog for open attached file in #1 on form and show it on picture box . can send a sample for fix problem?
    2-i can not show name of it on label(???? name problem) - can send a sample for fix problem?

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,208

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Quote Originally Posted by Black_Storm View Post
    i created a product for a company to work for open images and show in picturebox and show name it on a label or...
    If you are going to create a product for a non-English based system, you should start to learn and understand unicode and how to make your project compatible.

    There are plenty of projects in the codebank to include substitutes for the common dialog, labels, and more.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11
    Addicted Member
    Join Date
    Sep 2014
    Posts
    145

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    My request for the original file with a non-English name had been completely ignored, so I am out of this thread. (My intention was to test out an Iranian file name before offering my small project which I happen to have - about 5 years ago I got a bundle of photos, some of them with non-English names, so I created the said small project. Because I was not sure whether it would also be the same good on an Iranian file name, I though I better had a test first.)

    Before leaving, I would like to mention two relevant points, for the benefit of the thread initiator:

    (1) Nowadays many photos have an ICC color profile; a good project should be able to present ICC-converted images to viewers.

    (2) By a great majority, photos are taken at Orientation 1; however, there may be some with Orientation 2 to 8. A good project dealing with JPG files should be able to provide an auto-orientation of photos (like Windows 10 does in File Explorer). Failing that, then buttons should be provided for users to manually rotate on the spot.

  12. #12

    Thread Starter
    Addicted Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Posts
    180

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    i fixed problem by this thread (#8) but problem 2 not fixed yet

    i created this label support unicode (attached) but i think this is so complicated,any body can send a simple label user control or better way for show uncode charachters on a label(transparent is matter for me)
    Attached Files Attached Files
    Last edited by Black_Storm; Feb 16th, 2018 at 02:41 AM. Reason: better edit

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,178

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Here's an RTF label (and button) I use often. I don't use them in multi-lingual situations, but I do use them to "get at" many of the special characters of Unicode that you can't get at via a regular label. Maybe they'll do what you're trying to do. Basically, they're just piggy-backing on the RTB control.

    Alternatively, you could just directly use the RTB as a label. That'd also probably work for you, but you would have to load it with Unicode at runtime. The nicety of mine is that it's got a little IDE editor with it.

    Good Luck,
    Elroy

    EDIT1: I've never used it, but the InkEdit control is also suppose to have some nice features.
    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. Please understand that Ive been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a VB6 random code folder that is overflowing. Ive been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  14. #14
    Fanatic Member
    Join Date
    May 2014
    Location
    Preveza Greece
    Posts
    929

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    1. Use this to convert longpath (unicode) to a proper DosPath (it is in a unicode string but letters are in system codepage, as a direct conversion of a DosPath to unicode, so VB convert it to Ansi when you work with Open).

    Code:
    Declare Function GetShortPathName Lib "KERNEL32" Alias _
    "GetShortPathNameW" (ByVal lpszLongPath As Long, _
    ByVal lpszShortPath As Long, ByVal cchBuffer As Long) As Long
    
    Public Function GetDosPath(LongPath As String) As String
    
    Dim s As String
    Dim i As Long
    Dim PathLength As Long
    
            i = Len(LongPath) * 2 + 2
    
            s = String(1024, 0)
    
            PathLength = GetShortPathName(StrPtr(LongPath), StrPtr(s), i)
    
            GetDosPath = Left$(s, PathLength)
    
    End Function
    So you can use dospath as a filename to open it.

    2. You need a way to draw on picture dc using hdc, and a RECT with proper values (values are in pixels).

    Code:
    Private Const DT_NOPREFIX As Long = &H800&
    Private Const DT_SINGLELINE As Long = &H20&
    Private Const DT_NOCLIP As Long = &H100&
    Private Const DT_VCENTER As Long = &H4&
    
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    Private Declare Function DrawText Lib "User32" Alias "DrawTextW" (ByVal hDC As Long, ByVal lpStr As Long, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
    
    
    Private Sub PrintItem(mHdc As Long, c As String, r As RECT, Optional way As Long = DT_SINGLELINE Or DT_NOPREFIX Or DT_NOCLIP Or DT_VCENTER)
        DrawText mHdc, StrPtr(c), -1, r, way
    End Sub
    3. If you need to create a file with full unicode filename you need something else. You have to make a file in another way, and then you get the DosPath to append data.

    Code:
    Public Declare Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As Long)
    Declare Function CreateFile Lib "KERNEL32" Alias "CreateFileW" (ByVal lpFileName As Long, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    Public Const GENERIC_WRITE = &H40000000
    Public Const FILE_ATTRIBUTE_NORMAL = &H80
    Declare Function FlushFileBuffers Lib "KERNEL32" (ByVal hFile As Long) As Long
    Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
    
    Public Function NeoUnicodeFile(FileName$) As Boolean
    Dim hFile, counter
    Dim f$, f1$
    Sleep 10
    If Left$(FileName$, 2) <> "\\" Then
    f$ = "\\?\" + FileName$
    Else
    f$ = FileName$
    End If
    On Error Resume Next
    f1$ = Dir(f$)  '' THIS IS THEWORKAROUND FOR THE PROBLEMATIC CREATIFILE (I GOT SOME HANGS)
    
    hFile = CreateFile(StrPtr(f$), GENERIC_WRITE, ByVal 0, ByVal 0, 2, FILE_ATTRIBUTE_NORMAL, ByVal 0)
    FlushFileBuffers hFile
    Sleep 10
    
    CloseHandle hFile
    
    NeoUnicodeFile = GetDosPath(f$)<> ""
    
    Sleep 10
    
    'need "\\?\" before
    
    'now we can use the getdospath from normal Open File
    
    
    End Function
    Last edited by georgekar; Feb 16th, 2018 at 08:28 AM.

  15. #15

    Thread Starter
    Addicted Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Posts
    180

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    how can get data of file droped like as string?
    its matter for me to string data because i need post this data like as string with xml.

    for examle i want keep data of (تصویر.exe or متن.png or نمونه تصویر.pdf) in a string and after my processed then save it as orginal format ( exe or png or pdf).

  16. #16
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,137

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Did you try squirting data.files(1) into George's GetDosPath Function yet?
    Just a suggestion I'm not testing here.

  17. #17

    Thread Starter
    Addicted Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Posts
    180

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Quote Originally Posted by Magic Ink View Post
    Did you try squirting data.files(1) into George's GetDosPath Function yet?
    Just a suggestion I'm not testing here.
    what ur means?
    can u send sample code?

  18. #18
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,137

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    FileName$ = GetDosPath(data.files(1))
    ...perhaps

  19. #19
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,922

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    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:
    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
    You now have an array of the dropped filenames, in Unicode, in sFiles()


    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.

  20. #20

    Thread Starter
    Addicted Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Posts
    180

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Quote Originally Posted by fafalone View Post
    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:
    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
    You now have an array of the dropped filenames, in Unicode, in sFiles()


    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.
    my problem is about read content data,my question exits in this thread(http://www.vbforums.com/showthread.p...67#post5271567).

    i want read content data of files(file names is unicode names) and then can save same file with another name(unicode names) in other place.
    for example content data of 1.png is :
    IHDR a E صYش sRGB خ gAMA ڈ a pHYs أ أاod چIDATx^يطچآ0@ل”””)ƒپR%c0%#dŒ””œu…’ثء‚أژxKىH“LىT74444444444444444 44 44ٍu]كWU5.ف9ڈ1)kyŒNسeعbˆ–ا`*په0nض'Eم‹+?ظp8„ءiْ q‎ةFXiزQiBMKةفn<Uفnc kےr *ھعl65ئV„رهrYaَ]9@جF‎am]*کv/›Q3\\I*ي›b2MuRi*3
    *F؟~؟Fmغwد هق/ك†وسz@َز{رًL_u:تںد›go‎د*iqqqqqqqqqqqqqqqqqqqqqqqqqqQغ‎O 1ل IENDB`‚

    but in my thread when i am doing read content, content are like this :
    ‰PNG
    
    ? ? ? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ? ? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ? ? ???? ???? ???? ???? ???? ???? ???? ???? ??i qFXiQiBMKn<Unc kr žl65ƲV„rYa]9@Fam]*˜v/›Q3\\I*›b2MuRi*3
    *F~Fmۦw /†z@{L_u:Ÿ›gožiqqqqqqqqqqqqqqqqqqqqqqqqqqQO1  IENDB`‚

  21. #21

    Thread Starter
    Addicted Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Posts
    180

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    Quote Originally Posted by fafalone View Post
    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:
    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
    You now have an array of the dropped filenames, in Unicode, in sFiles()


    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.
    whats this?
    my problem is about content data of files.
    my thread is in (http://www.vbforums.com/showthread.p...67#post5271567)

  22. #22
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,922

    Re: ole drag drop and problem with unicode charachters or load image with unicode

    I was answering the question posed when you started this thread. You said you wanted to use OLEDragDrop, and that it was returning filenames with ? instead of Unicode characters in Data.Files(). My response concerned how to retrieve the filename from OLEDragDrop with the proper Unicode characters (a prerequisite to reading the data).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width


×
By using this site, you agree to the Privacy Policy