什么?不可能没有。微软不会那么笨把这个函数都给漏掉了。是可恶的 API Viewer 有错误。'API Viewer 声明: Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectory" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long'Alias "GetCurrentDirectory" 应该是 Alias "GetCurrentDirectoryA" 'ANSI 版本VBA的 CurDir 功能一样.to unrknight(安装失败) : 当前路径和程序路径不一样。
同意楼上的意见。如果非用不可,那么win2000是Unicode版的,相应的和字符串有关的API都以W结尾(NT为了兼容,同时包含A和W版,2000里是否还包含部分A版的,本人没研究)。速度快,但带来兼容的问题。 声明如下 Private Declare Function GetCurrentDirectoryW Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As Long) As Long 或 Private Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectoryW" (ByVal nBufferLength As Long, ByVal lpBuffer As Long) As LongPrivate Sub Command1_Click()Dim s As String s = String(260, 0)GetCurrentDirectoryW 260, StrPtr(s)MsgBox sEnd Sub
当然,返回的结果还得处理: length = InStr(s, Chr(0)) If length > 0 Then s = Left(s, length - 1) End If
Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectory" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long'Alias "GetCurrentDirectory" 应该是 Alias "GetCurrentDirectoryA" 'ANSI 版本VBA的 CurDir 功能一样.to unrknight(安装失败) :
当前路径和程序路径不一样。
声明如下
Private Declare Function GetCurrentDirectoryW Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As Long) As Long
或
Private Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectoryW" (ByVal nBufferLength As Long, ByVal lpBuffer As Long) As LongPrivate Sub Command1_Click()Dim s As String
s = String(260, 0)GetCurrentDirectoryW 260, StrPtr(s)MsgBox sEnd Sub
length = InStr(s, Chr(0))
If length > 0 Then
s = Left(s, length - 1)
End If