Function to retrieve a temporary file name using GetTempFileName API call
Function to retrieve a temporary file name using GetTempFileName API call
API Declarations
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 Const MAX_PATH = 260
Rate Function to retrieve a temporary file name using GetTempFileName API call
(2(2 Vote))
Dim lngReturn As Long
Dim strTempFile As String
Dim strWindowsTempDir As String
'get the computers Windows temporary directory
strWindowsTempDir = Space$(MAX_PATH)
'get the folder
lngReturn = GetTempPath(MAX_PATH, strWindowsTempDir)
'parse nameup to null terminator
strWindowsTempDir = Left$(strWindowsTempDir, lngReturn)
'pad a working string
strTempFile = Space$(MAX_PATH)
'if user did not pass optional file prefix, make it TMP
If FilePrefix = "" Then
FilePrefix = "TMP"
End If
lngReturn = GetTempFileName(strWindowsTempDir, FilePrefix, 0, strTempFile)
'Falure returns 0
If lngReturn <> 0 Then
'strip null character
strTempFile = Left$(strTempFile, InStr(strTempFile, Chr$(0)) - 1)
TemporaryFile = strTempFile
End If
End Function
Function to retrieve a temporary file name using GetTempFileName API call Comments
No comments yet — be the first to post one!
Post a Comment