说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

VB取得临时文件名

HTML文档下载 WORD文档下载 PDF文档下载
VB取得临时文件名
声明:
Public Const MAX_PATH = 260

Public 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
Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

代码:
Public Function GetTempFile() As String
Dim lngRet As Long
Dim strBuffer As String, strTempPath As String

'初始化 buffer
strBuffer = String$(MAX_PATH, 0)

'取得临时路径
lngRet = GetTempPath(Len(strBuffer), strBuffer)

'0 错误
If lngRet = 0 Then Exit Function

'去掉尾中的 null
strTempPath = Left$(strBuffer, lngRet)

'初始化 buffer
strBuffer = String$(MAX_PATH, 0)

'取得临时文件名
lngRet = GetTempFileName(strTempPath, "tmp", 0&, strBuffer)

If lngRet = 0 Then Exit Function

lngRet = InStr(1, strBuffer, Chr(0))
If lngRet > 0 Then
GetTempFile = Left$(strBuffer, lngRet - 1)
Else
GetTempFile = strBuffer
End If
End Function

备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘