int GetTempFileName(cDriveLetter,lpPrefixString,wUnique,lpTempFileName)
This function creates a temporary filename of the following form:
drive:\path\prefixuuuu.tmp
In this syntax line, drive is the drive letter specified by the cDriveLetter parameter; path is the pathname of the temporary file (either the root directory of the specified drive or the directory specified in the TEMP environment variable); prefix is all the letters (up to the first three) of the string pointed to by the lpPrefixString parameter; and uuuu is the hexadecimal value of the number specified by the wUnique parameter.
Parameter | Type/Description |
cDriveLetter | BYTE Specifies the suggested drive for the temporary filename. If cDriveLetter is zero, the default drive is used. | |
lpPrefixString | LPSTR Points to a null-terminated character string to be used as the temporary filename prefix. This string must consist of characters in the OEM-defined character set. | |
wUnique | WORD Specifies an unsigned short integer. | |
lpTempFileName | LPSTR Points to the buffer that is to receive the temporary filename. This string consists of characters in the OEM-defined character set. This buffer should be at least 144 bytes in length to allow sufficient room for the pathname. |
The return value specifies a unique numeric value used in the temporary filename. If a nonzero value was given for the wUnique parameter, the return value specifies this same number.
To avoid problems resulting from converting OEM character an string to an ANSI string, an application should call the _lopen function to create the temporary file.
The GetTempFileName function uses the suggested drive letter for creating the temporary filename, except in the following cases:
If a hard disk is present, GetTempFileName always uses the drive letter of the first hard disk.
Otherwise, if a TEMP environment variable is defined and its value begins with a drive letter, that drive letter is used.
If the TF_FORCEDRIVE bit of the cDriveLetter parameter is set, the above exceptions
do not apply. The temporary filename will always be created in the current directory of
the drive specified by cDriveLetter, regardless of the presence of a hard disk or the TEMP environment variable.
If the wUnique parameter is zero, GetTempFileName attempts to form a unique number based on the current system time. If a file with the resulting filename exists, the number is increased by one and the test for existence is repeated. This continues until a unique filename is found; GetTempFileName then creates a file by that name and closes it. No attempt is made to create and open the file when wUnique is nonzero.