Working Directory and File issues

I'm running into working directory issues where I need to open a file from the base directory/templates. If you click on the shortcut the installation creates, the file can't be found. I figure this is because the program is trying to open /teamplates/file and the working directory is who knows where! My solution is to read from the registry to get the installation base directory and go from there. This seems kind of stupid to have to read the registry whenever I need to access a file. Is there any easier way. I suppose I could read the variable once when my View gets created, then pass it to all its members who need it... And what about testing? Am I going to create a fake entry for now until I get towards final testing where installwizard creates its own entries? Comments anyone?!

Justin Deltener
deltener@mindtremors.com
DredwickAsked:
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.

chensuCommented:
Yes, you can read the registry key once your application starts. You don't have to do it every time you access a file. Another way is to consider the full path name of your application as the base directory. For example,

TCHAR pszBuf[_MAX_PATH];
::GetModuleFileName(NULL, pszBuf, sizeof(pszBuf) / sizeof(TCHAR));
*::_tcsrchr(pszBuf, _T('\\')) = _T('\0');
::lstrcat(pszBuf, _T("\\teamplates\\thefile.ext"));
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
DredwickAuthor Commented:
I've never even heard of the GetModuleFileName function. Perfect solution! Exactly what I needed, Great Job!
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.