释义 |
GetTempFileName 语法: C++ UINT WINAPI GetTempFileName( __in LPCTSTR lpPathName, __in LPCTSTR lpPrefixString, __in UINT uUnique, __out LPTSTR lpTempFileName ); GetTempFileName函数 创建一个临时文件的名称。如果一个唯一的文件名生成,一个空文件创建和处理它被释放,否则,只有一个文件名生成。 参数 lpPathName [in] 为文件名的目录路径。应用程序通常指定一个句号(。)当前目录或GetTempPath函数的结果。该字符串的长度不能超过MAX_PATH - 14个字符或GetTempFileName将失败。如果该参数为NULL,则函数失败。 lpPrefixString [in] 空结尾的前缀字符串。该函数使用最多的前三个作为文件名前缀字符串字符。此字符串必须包括在OEM字符定义的字符集。 uUnique [in] 一个无符号的整数,用于创建临时文件的名称。有关更多信息,请参见备注。 如果uUnique是零,函数试图形成一个唯一的文件名,使用当前系统时间。如果该文件已经存在,这个数字增加了1和功能的检验,如果此文件已经存在。这一直持续到一个唯一的文件名被发现,该函数创建一个同名文件并关闭它。请注意,该函数不尝试验证该文件的名称的唯一性不为零时uUnique。 lpTempFileName [out] 一个缓冲区,它接收临时文件名的指针。此缓冲区应该MAX_PATH字符,以适应路径再加终止空字符。 返回值 如果函数成功,返回值指定的唯一的数字值在临时文件的名称。如果uUnique参数不为零,则返回值指定的数目相同。 如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。 下面是一个可能的返回值。 返回valueDescription ERROR_BUFFER_OVERFLOWThe字符串的长度指出的lpPathName参数更比MAX_PATH - 14个字符。 备注 该GetTempFileName函数创建一个如下形式的临时文件的名称: <路径\\ 。川芎嗪 下表描述了文件名语法。 ComponentMeaning <路径路径参数指定的lpPathName
前三个字母串的lpPrefixString 十六进制值uUnique 如果uUnique是零,GetTempFileName创建一个空文件,并关闭它。如果uUnique不为零,则必须自己创建该文件。只有一个文件名,创建,因为GetTempFileName不能保证该文件的名称是唯一的。 只有低16位的uUnique参数使用。这限制了GetTempFileName到65,535个唯一的文件名称的最大如果lpPathName和lpPrefixString参数保持不变。 由于用来生成文件名的算法,GetTempFileName业绩不佳时,可以创建一个文件具有相同前缀的大量。在这种情况下,建议您构造独特的文件的GUID的名称。 临时的名字被这个函数创建的文件不会自动删除。要删除这些文件要求的DeleteFile。 为了避免出现问题时产生的ANSI字符串转换,应用程序应调用CreateFile函数来创建一个临时文件。 实例 有关示例,请参见创建和使用临时文件。 要求: 最低支持:client-Windows 2000专业版 最低支持server-Windows 2000服务器 HeaderWinBase.h(头文件:winuser.h) LibraryKernel32.lib DLLKernel32.dll Unicode和ANSI namesGetTempFileNameW(Unicode)和GetTempFileNameA(ANSI)的 参见 文件管理函数 CreateFile 的DeleteFile GetTempPath 如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com) 生成日期:2009年9月3日 ==英文原文==GetTempFileName Function Creates a name for a temporary file. If a unique file name is generated, an empty file is created and the handle to it is released; otherwise, only a file name is generated. Syntax C++ UINT WINAPI GetTempFileName( __in LPCTSTR lpPathName, __in LPCTSTR lpPrefixString, __in UINT uUnique, __out LPTSTR lpTempFileName ); Parameters lpPathName [in] The directory path for the file name. Applications typically specify a period (.) for the current directory or the result of the GetTempPath function. The string cannot be longer than MAX_PATH–14 characters or GetTempFileName will fail. If this parameter is NULL, the function fails. lpPrefixString [in] The null-terminated prefix string. The function uses up to the first three characters of this string as the prefix of the file name. This string must consist of characters in the OEM-defined character set. uUnique [in] An unsigned integer to be used in creating the temporary file name. For more information, see Remarks. If uUnique is zero, the function attempts to form a unique file name using the current system time. If the file already exists, the number is increased by one and the functions tests if this file already exists. This continues until a unique filename is found; the function creates a file by that name and closes it. Note that the function does not attempt to verify the uniqueness of the file name when uUnique is nonzero. lpTempFileName [out] A pointer to the buffer that receives the temporary file name. This buffer should be MAX_PATH characters to accommodate the path plus the terminating null character. Return Value If the function succeeds, the return value specifies the unique numeric value used in the temporary file name. If the uUnique parameter is nonzero, the return value specifies that same number. If the function fails, the return value is zero. To get extended error information, call GetLastError . The following is a possible return value. Return valueDescription ERROR_BUFFER_OVERFLOWThe length of the string pointed to by the lpPathName parameter is more than MAX_PATH–14 characters. Remarks The GetTempFileName function creates a temporary file name of the following form: \\.TMP The following table describes the file name syntax. ComponentMeaning Path specified by the lpPathName parameter
First three letters of the lpPrefixString string Hexadecimal value of uUnique If uUnique is zero, GetTempFileName creates an empty file and closes it. If uUnique is not zero, you must create the file yourself. Only a file name is created, because GetTempFileName is not able to guarantee that the file name is unique. Only the lower 16 bits of the uUnique parameter are used. This limits GetTempFileName to a maximum of 65,535 unique file names if the lpPathName and lpPrefixString parameters remain the same. Due to the algorithm used to generate file names, GetTempFileName can perform poorly when creating a large number of files with the same prefix. In such cases, it is recommended that you construct unique file names based on GUIDs. Temporary files whose names have been created by this function are not automatically deleted. To delete these files call DeleteFile . To avoid problems resulting when converting an ANSI string, an application should call the CreateFile function to create a temporary file. Examples For an example, see Creating and Using a Temporary File . Requirements Minimum supported clientWindows 2000 Professional Minimum supported serverWindows 2000 Server HeaderWinBase.h (include Windows.h) LibraryKernel32.lib DLLKernel32.dll Unicode and ANSI namesGetTempFileNameW (Unicode) and GetTempFileNameA (ANSI) See Also File Management Functions CreateFile DeleteFile GetTempPath Send comments about this topic to Microsoft Build date: 9/3/2009 ==原始网址==http://msdn.microsoft.com/en-us/library/aa364991(VS.85).aspx\n |