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.
sean_Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.