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.
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.

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.

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.
Are you open it (second) with the same name? You have to call GetTempFileName() for each new file you would like to have.
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?
Yes, it should.
sean_Author Commented:
Thank you, I finally got it working!
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.