Get full path with Unicode file name

前端 未结 2 1304
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 22:37

I have a path in short version or in DOS format (\"C:/DOCUME~1\" e.g) and want to get the full path/long path of it (\"C:/Documents And Settings\"

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-20 23:18

    To use W-functions from vb6/vba, you declare all string parameters as long:

    Private Declare Function GetLongPathName Lib "kernel32" Alias "GetLongPathNameW" _
      (ByVal lpszShortPath As Long, _
       ByVal lpszLongPath As Long, _
       ByVal cchBuffer As Long) As Long
    

    and pass StrPtr(a_string) instead of just a_string.

    So if you had:

    dim s_path as string
    dim l_path as string
    
    s_path = "C:\DOCUME~1"
    l_path = string$(1024, vbnullchar)
    
    GetLongPathNameA s_path, l_path, len(l_path)
    

    it would become

    dim s_path as string
    dim l_path as string
    
    s_path = "C:\DOCUME~1"
    l_path = string$(1024, vbnullchar)
    
    GetLongPathNameW strptr(s_path), strptr(l_path), len(l_path)
    

提交回复
热议问题