Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As LongPrivate Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Sub Form_Click()
Dim temppath As String * 255, tempfilex As String * 255
x = GetTempPath(255, temppath)
temppath = Left(tempfilex, x)
x = GetTempFileName(temppath, "API", 0, tempfilex)
tempfile = Left(Trim(tempfilex), Len(Trim(tempfilex)))
Print "temporary filename is:"
Print tempfile
Print Len(t)
End Sub
Private Sub Form_Click()
Dim temppath As String * 255, tempfilex As String * 255
x = GetTempPath(255, temppath)
temppath = Left(tempfilex, x)
x = GetTempFileName(temppath, "API", 0, tempfilex)
tempfile = Left(Trim(tempfilex), Len(Trim(tempfilex)))
Print "temporary filename is:"
Print tempfile
Print Len(t)
End Sub
改为
temppath = Left(temppath, x)
Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
注意,其中lpszPath As String不能是定长字符串。所以要这样:
Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As LongPrivate Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Sub Form_Click()
Dim temppath As String * 255, tempfilex As String * 255
x = GetTempPath(255, temppath)
x = GetTempFileName(Left(temppath, x), "API", 0, tempfilex)
tempfile = Left(Trim(tempfilex), Len(Trim(tempfilex)))
Print "temporary filename is:"
Print tempfilePrint Len(t)
End Sub