[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

how do i use GetTempFilename?

I need to use GetTempFileName to create unique filenames for temporary files that are created in my program.  Could somebody please explain how to use this function?

Thanks, Sean.
0
sean_
Asked:
sean_
  • 3
  • 3
1 Solution
 
MichaelSCommented:
TCHAR                  szTempFileName[MAX_PATH];
TCHAR                  szTempPath[MAX_PATH];

GetTempPath(MAX_PATH, szTempPath);
GetTempFileName(szTempPath, "~", 0, szTempFileName);

After this you will have name of temp file in szTempFileName.
0
 
sean_Author Commented:
I have used your code as is and then followed it by

file.Open( szTempFileName, CFile::modeCreate | CFile::modeWrite, &e );

where file is of type CFile.  This works okay for my first file, but I get an assertion failure when I open a second file.
0
 
MichaelSCommented:
Are you open it (second) with the same name? You have to call GetTempFileName() for each new file you would like to have.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
sean_Author Commented:
I call you code every time I open a new file.  Does this create a different file name everytime?
0
 
MichaelSCommented:
Yes, it should.
0
 
sean_Author Commented:
Thank you, I finally got it working!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now