GetTempFileName

Synopsis

                
                    WIN32_FILETIME GetTempFileName(
                        LPSTR lpTemplatePath,
                        LPSTR lpPrefix,
                        DWORD nRandomize,
                        LPWIN32_FILETIME lpFindFileData
                    );
                
            

Description

This function generates a temporary filename and returns it to the calling application. It creates a filename consisting of the specified prefix followed by a randomly generated suffix. The filename is created in the current directory.

Parameters

LPSTR lpTemplatePath: Pointer to a null-terminated string containing the base name for the temporary file. This string is not modified.
LPSTR lpPrefix: Pointer to a null-terminated string containing the prefix to be used for the temporary file name.
DWORD nRandomize: Specifies the level of randomization to be applied to the random suffix. - 0: No randomization. - 1: 16-bit randomization. - 2: 32-bit randomization.
LPWIN32_FILETIME lpFindFileData: Pointer to a WIN32_FILETIME structure that is filled in with the creation time of the temporary file.

Return Value

Returns NULL if the function fails. Otherwise, returns a pointer to a null-terminated string containing the generated temporary filename.

Example

                    
                        #include <iostream>
                        #include <string>

                        int main() {
                            std::string tempFileName;
                            if (GetTempFileName(&tempFileName[0], "temp", 2, NULL) == NULL) {
                                std::cerr << "GetTempFileName failed" << std::endl;
                                return 1;
                            }

                            std::cout << "Temporary filename: " << tempFileName << std::endl;

                            return 0;
                        }
                    
                

See Also