Results 1 to 5 of 5

Thread: [RESOLVED] Unicode file name from OLEDrop data.Files

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2011
    Location
    Stockholm, Sweden
    Posts
    45

    Resolved [RESOLVED] Unicode file name from OLEDrop data.Files

    Hi

    I'm trying to drop files with unicode names into my app but it seems to fail.
    A function that gets the last edit date using CreateFileW+GetFileTime works fine when I pass the path and file from other sources (like my codejock open file dialog) But when the path and file name variable is set from the data.Files array (variant) it fails since CreateFileW returns -1. I suspect the vb6 OLEDrop.Files collection does not contain the proper unicode filenames. Can anybody confirm this and suggest a workaround. One strange thing is that DIR (used to verify that the file exists) returns correctly from both sources...

  2. #2
    Hyperactive Member
    Join Date
    May 2012
    Posts
    339

    Re: Unicode file name from OLEDrop data.Files

    plz give code

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2011
    Location
    Stockholm, Sweden
    Posts
    45

    Re: Unicode file name from OLEDrop data.Files

    Hi

    I have so far confirmed that the code (below) works fine to get the date from a string both ansi and unicode. I have also confirmed that the problem is that the string I get from the DataObjectFiles collection of the OLEDrop event does NOT contain the unicode characters. The debug.print in the function returns 63 (questionmark) if it is the DataObjects.Files string while it returns 22030 if the strings comes from my fileopen common dialog code. The file name is:
    嘎伽嘎ㅈ퓨_2008-03-04_18-17-54.JPG
    and starts at character 31 after the path. I use the same file for both the open file dialog and my OLE draganddrop operation.
    The DIR strangeness was simply explained by that the questionmarks that replaces the unicode characters in my string were treated as wildcards by DIR and the file was therefore "found".
    So I think this comes down to: How can we get the unicode file names from the OLE data structure?
    A screenshot in this article sort of indicates there are two files collections in the actual object but I guess vb6 only gives us the non-W files collection...
    http://www.codeproject.com/Articles/...en-Your-Progra

    Code:
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileW" (ByVal lpFileName As Long, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    
           
    Private Function GetFileDate(ByVal sfilePath As String) As Date
    
        Dim lngHandle As Long
        Dim hFile As Long
        Dim udtFileTime As FILETIME, SysTime As SYSTEMTIME
        Dim flagsnattr As Long
        Debug.Print "Ascw of first unicode char in string: " & AscW(Mid(sfilePath, 31, 1))
        flagsnattr = FILE_ATTRIBUTE_ARCHIVE Or FILE_ATTRIBUTE_HIDDEN Or FILE_ATTRIBUTE_NORMAL Or FILE_ATTRIBUTE_READONLY Or FILE_ATTRIBUTE_SYSTEM
        lngHandle = CreateFile(StrPtr(sfilePath), GENERIC_READ, FILE_SHARE_READ, ByVal 0&, OPEN_ALWAYS, flagsnattr, ByVal 0&)
        GetFileTime lngHandle, udtFileTime, udtFileTime, udtFileTime
        FileTimeToLocalFileTime udtFileTime, udtFileTime
        FileTimeToSystemTime udtFileTime, SysTime
        CloseHandle lngHandle
        GetFileDate = DateSerial(LTrim(Str$(SysTime.wYear)), LTrim(Str$(SysTime.wMonth)), LTrim(Str$(SysTime.wDay))) _
            + TimeSerial(LTrim(Str$(SysTime.wHour)), LTrim(Str$(SysTime.wMinute)), LTrim(Str$(SysTime.wSecond)))
           
    End Function

  4. #4
    Fanatic Member DrUnicode's Avatar
    Join Date
    Mar 2008
    Location
    Natal, Brazil
    Posts
    631

    Re: Unicode file name from OLEDrop data.Files

    To get Unicode filenames from DragDrop by Keith LaVolpe.
    http://cyberactivex.com/UnicodeTutor...gDrop_or_Paste
    Zipped project file:
    http://www.cyberactivex.com/download/UnicodeDND.zip

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2011
    Location
    Stockholm, Sweden
    Posts
    45

    Re: Unicode file name from OLEDrop data.Files

    Sorry did not have time to try this until now but that worked perfectly. Thanks DrUniCode (and LaVolpe)!

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
  •  



Click Here to Expand Forum to Full Width