Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function creates a name for a temporary file. The file name is the concatenation of specified path and prefix strings, a hexadecimal string formed from a specified integer, and the .TMP extension.

If you specify an integer other than zero, the function creates the file name, but does not create the file. If you specify zero for the integer, the function creates a unique file name and creates the file in the specified directory.

Syntax

UINT GetTempFileName(
  LPCTSTR 
lpPathName, 
  LPCTSTR 
lpPrefixString, 
  UINT 
uUnique, 
  LPTSTR 
lpTempFileName
);

Parameters

lpPathName

[in] Points to a null-terminated string that specifies the directory path for the file name. This string must consist of characters in the ANSI character set. Because the concept of a current directory does not exist in Windows Embedded CE, you must specify the full directory path. If this parameter is set to NULL, the function fails.

lpPrefixString

[in] Points to a null-terminated prefix string. The function uses the first three characters of this string as the prefix of the file name. This string must consist of characters in the ANSI character set.

uUnique

[in] Specifies an unsigned integer that the function converts to a hexadecimal string for use in creating the temporary file name.

If this parameter is set to nonzero, the function appends the hexadecimal string to lpPrefixStringto form the temporary file name. In this case, the function does not create the specified file, and does not test whether the file name is unique.

If this parameter is set to 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 file name, and then it creates the file in the lpPathNamedirectory.

lpTempFileName

[out] Pointer to the buffer that receives the temporary file name. This null-terminated string consists of characters in the ANSI character set. To accommodate the path, this buffer must be at least the length, in bytes, specified by MAX_PATH.

Return Value

The unique numeric value used in the temporary file name indicates success. If uUniqueis set to nonzero, the return value specifies that number. Zero indicates failure. To get extended error information, call GetLastError.

Remarks

This function creates a temporary file name. The following code example shows the form of the temporary file name.

Copy Code
path\preuuuu.TMP 

The following table describes the file name syntax.

Component Description

path

Path specified by lpPathName.

pre

First three letters of the lpPrefixStringstring.

uuuu

Hexadecimal value of uUnique.

When a Windows Embedded CE-based device is turned off, temporary files whose names have been created by this function are not automatically deleted.

To avoid problems resulting from converting an ANSI character set string to a Windows string, the CreateFilefunction to create a temporary file.

If uUniqueis set to zero, This function attempts to form a unique number based on the current system time. If a file with the resulting file name exists, another number is generated, and the test for existence is repeated. Testing continues until a unique file name is found. This function then creates a file by that name and closes it. When uUniqueis set to nonzero, no attempt is made to create and open the file.

Windows Embedded CE pads a file name with zeros when it has fewer than four hexadecimal digits in its name. For example, a Windows desktop OS creates < File Name>34.tmp, whereas Windows Embedded CE creates < File Name>0034.tmp.

Requirements

Header winbase.h
Library coredll.lib
Windows Embedded CE Windows CE 3.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also