?
Solved

how do i use GetTempFilename?

Posted on 1999-06-30
6
Medium Priority
?
609 Views
Last Modified: 2013-11-20
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
Comment
Question by:sean_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 6

Accepted Solution

by:
MichaelS earned 400 total points
ID: 1308522
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
 

Author Comment

by:sean_
ID: 1308523
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
 
LVL 6

Expert Comment

by:MichaelS
ID: 1308524
Are you open it (second) with the same name? You have to call GetTempFileName() for each new file you would like to have.
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:sean_
ID: 1308525
I call you code every time I open a new file.  Does this create a different file name everytime?
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 1308526
Yes, it should.
0
 

Author Comment

by:sean_
ID: 1308527
Thank you, I finally got it working!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question