Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

GetCurrentDirectory (while debugging)

This topic is 6335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I hope I have posted this in the correct forum. Here is my question. I use the win32 api function ''GetCurrentDirectory'' to get a path to the directory that my application is running from. This is so that I can use the win32 file searching function to search for files in directories relative to my application''s directory. This in itself works fine, the problem occurs when I run in DEBUG mode. For a while, I wandered why my images didnt load in debug mode, then I realized that GetCurrentDirectory was not returning the correct path. I imagine that the path returned by this function is where the debugger resides. Is there any way to retrieve my application''s actual path while running the debugger? Or should I simply do something like: #if DEBUG ... and have a static pathname? If i choose to do the ''#if..'' approach, how do I check whether it is being built for debug? I remember seeing this somewhere, I think it was like: ''__debug__'' or something. does anyone know for sure?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You could try this for retrieving the directory of the executable:

TCHAR szPath[_MAX_PATH];
GetModuleFileName(NULL, szPath, sizeof(szPath) / sizeof(TCHAR));

for (int i = sizeof(szPath) / sizeof(TCHAR); i >= 0; i--)
{
if (szPath == ''\'')
{
szPath[i] = ''\0'';
break;
}
}

This basically retrieves the path of the executable (e.g., "c:\blah\blah.exe"), and then changes the ''\'' closest to the right to a NULL terminator (e.g., the string would become "c:\blah").
This general concept should work, although I am not certain if there may be a better way to do this.

--Rob D

Share this post


Link to post
Share on other sites
Assuming you are using Visual C++, try setting your debug working directory to the directory you want to use. It''s in project settings under the debug tab.

Regards

Starfall

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!