2.1.10.30 GetTempFileName


Description

This function creates a name for a temporary file.


This function constructs a temporary file name in the Windows Temp path.

Syntax

DWORD GetTempFileName( LPCSTR lpPathName, LPCSTR lpPrefixString, DWORD uUnique, LPSTR lpTempFileName )


BOOL GetTempFileName( string & strFile, LPCSTR lpcszPrefix = NULL )

Parameters

lpPathName
[input] A null-terminated string that specifies the directory path for the filename.
lpPrefixString
[input] A null-terminated prefix string. The function uses the first three characters of this string as the prefix of the filename.
uUnique
[input] An unsigned integer that the function converts to a hexadecimal string for use in creating the temporary filename.
If nonzero, the function appends the hex adecimal string to lpPrefixString. In this case, the function does not create the specified file nor test whether the filename is unique.
If zero, the function uses a hexadecimal string derived from the current system time. In this case, the function uses different values until it finds a unique filename, and then it creates the file in the lpPathName directory.
lpTempFileName
[output] Buffer that receives the filename. The buffer size should be at least MAX_PATH.


strFile
[output]a string to receive the temp file full path file name.
lpcszPrefix
[input] The function uses the first three characters of this string as the prefix of the file name.
If left as NULL, "OTF" will be used.

Return

If the function succeeds, the return value specifies the unique numeric value used in the temporary filename.

If the uUnique parameter is nonzero, the return value specifies that same number.

If the function fails, the return value is zero.


TRUE if success, FALSE if not able to fine a temp path.

Examples

EX1

int GetTempFileName_ex1()
{
    string strFile;
    char sz[MAXFULLPATH];
    DWORD dw = GetTempPath(MAXFULLPATH, sz);
    if( dw )
    {
        strFile = sz;
        dw = GetTempFileName(strFile, "Origin", 0, sz);
        if( dw )
            strFile = sz;
        else
            strFile.Empty();
    }
    out_str(strFile);
    return 1;
}


EX2

int GetTempFileName_ex2()
{
    string strTempFile;
    if(GetTempFileName(strTempFile,"ABC"))
    {
        printf("You can use this file name as temp file:%s\n", strTempFile);
    }
    return 0;
}

Remark

See Also

GetTempPath

Header to Include

origin.h

Reference