Results 1 to 2 of 2

Thread: Unicode aware VB6 functions replacement

  1. #1

    Thread Starter
    Member Dragokas's Avatar
    Join Date
    Aug 2015

    Unicode aware VB6 functions replacement


    here is W replacement for several native VB6 functions / properties:

    - Dir -> DirW()
    - MkDir -> MkDirW()
    - Environ -> EnvironW()
    - App.Path -> AppPathW()
    - App.ExeName -> AppExeNameW()
    - App.Major, Minor, Revision -> AppVersionW()

    All functions packed on archive as separate projects, available under the post below.

    1) DirW

    Prototype is: Dir$(Path with mask or backslash at the end, opt_mask of allowed attributes, opt_return folders? )

    Difference to original VB6 Dir$():

    Fixed bug, when Dir cannot handle attribute: read only (vbReadOnly)
    Added attributes:
    - reparse points (symlinks / junctions) (vbReparse)
    - all file objects (vbAll)
    - vbFile (files only, without folders)

    Enum VbFileAttribute "overloaded" by own: I removed all superfluous attributes, which original VB6 dir() are still not used in any way; I leave meaningful attributes only.

    + 3-rd optional argument (FoldersOnly); if true, it will filter files and leave folders only in output.
    Function also automatically filter folders-aliases "." и ".."

    Code based on earlier VB6() Dir$ reversing by @The Trick.

    2) MkDirW()

    Prototype is: MkDirW(Path to folder to create, opt_LastComponentIsFile as boolean) as boolean

    LastComponentIsFile - true, if you plan to specify filename as a last part of path component
    Return value: true, if successfully created or if folder is already exist

    3) EnvironW()

    Prototype: EnvironW$( "%Environment variable(s)%" )

    Difference to original VB6 Environ():

    - support several env. var-s on one line, like EnvironW("%UserName% - %UserDomain%")
    - require %var%, i.e. each environment variable should be surrounded by % signs.
    - automatically correct and "right" (in the sense, like if we wanted to do so from a 64-bit application) to expand under WOW64 such env. variables as:
    and get on 64-bit OS, respectively:
    - C:\Program Files, but not C:\Program Files (x86)
    - C:\Program Files\Common Files, but not C:\Program Files (x86)\Common Files

    4,5) AppPathW(), AppExeNameW()

    Prototypes are:
    - AppPathW$(opt_bGetFullPath as boolean)
    - AppExeNameW$(opt_WithExtension As Boolean)

        Debug.Print AppPathW()                          'Folder
        Debug.Print AppPathW(bGetFullPath:=True)        'Folder\FileName.extension
        Debug.Print AppExeNameW()                       'FileName
        Debug.Print AppExeNameW(WithExtension:=True)    'FileName.extension
    6) AppVersionW()

    Prototype is: AppVersionW$()

    # require AppPathW(), AppExeNameW()

    Just append unicode-char to your exe-name /and-or path (e.g. ALT + 3333) and you'll understand why you may need this function replacement.

    Returns: String, version of your program in format: Major.Minor.Build.Revision

    Best wishes,
    Attached Files Attached Files

  2. #2
    Frenzied Member
    Join Date
    Jun 2012

    Re: Unicode aware VB6 functions replacement

    Bug in the DirW function.

    Instead of
        If (Err.LastDllError) > 12& Then hFind = 0&: Err.Raise 52&
        Exit Function
    End If
    it should be
        hFind = 0&
        If (Err.LastDllError) > 12& Then Err.Raise 52&
        Exit Function
    End If
    You check always for "hFind <> 0&" and hFind of INVALID_HANDLE_VALUE would be also <> 0&. So the hFind must be reset to 0& regardless if an error shall be thrown out or not. (Err.LastDllError > 12&)

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