GetCurrentDirectory (while debugging)
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?
Seeing as you finally got your whole post out in one piece, may I suggest you promptly delete the other 2 .
Insomnia
Insomnia
Insomnia
January 14, 2001 04:29 PM
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 = ''\0'';<br> break;<br> }<br>}<br><br>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").<br>This general concept should work, although I am not certain if there may be a better way to do this.<br><br>–Rob D<br> </i>
TCHAR szPath[_MAX_PATH];
GetModuleFileName(NULL, szPath, sizeof(szPath) / sizeof(TCHAR));
for (int i = sizeof(szPath) / sizeof(TCHAR); i >= 0; i--)
{
if (szPath == ''\'')
{
szPath = ''\0'';<br> break;<br> }<br>}<br><br>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").<br>This general concept should work, although I am not certain if there may be a better way to do this.<br><br>–Rob D<br> </i>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement