如我们在使用REGSVR32.exe注册控件时,如果这个控件的路径中有空格或者文件名太长,就会注册不成功,因为REGSVR32.exe不支持长文件名,下面的函数就是解决这样的类似的问题
' 例如
' ? getShortPath("C:\Documents and Settings\Administrator\桌面\")
' C:\DOCUME~1\ADMINI~1\桌面\

'------------------------------------------------------------

Option Compare Database
Option Explicit

Private Declare Function GetShortPathName32 Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Public Function getShortPath(ByVal strFullPath As String) As String

    Dim strShortPath As String

    strShortPath = Space(256)
    GetShortPathName32 strFullPath, strShortPath, 256
    strShortPath = Left(strShortPath, InStr(strShortPath, Chr(0)) - 1)
    getShortPath = strShortPath

End Function


0 回复,0 引用: 返回长文件名的短文件名函数

添加回复

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。