VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Function to retrieve a temporary file name using GetTempFileName API call

by Anonymous (267 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Sun 17th January 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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




    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

Download this snippet    Add to My Saved Code

Function to retrieve a temporary file name using GetTempFileName API call Comments

No comments have been posted about Function to retrieve a temporary file name using GetTempFileName API call. Why not be the first to post a comment about Function to retrieve a temporary file name using GetTempFileName API call.

Post your comment

Subject:
Message:
0/1000 characters