Unable to specify relative filepaths when program is launched with Visual C++ 2010

Go To StackoverFlow.com

1

So the program compiles fine, and the executable is generated in $(SolutionDir)/Debug. When I run the executable from the debug folder itself, the program successfully scans the folder placed in the dubug directory for files. However, when I execute the program from Visual Studio, the program will fail unless i input the global path of that directory to the FindFirstFile function. Why?

For example: I have to do this in order to debug the program from Visual Studio:

#ifdef _DEBUG
#define FILEPATH L"C:/Users/Steven/Documents/Visual Studio 2010/Projects/$(SolutionDir)/Debug/Effects/*.dll"
#else
#define FILEPATH L"Effects/*.dll"
#endif
2012-04-04 22:17
by Steve Barna


1

Probably because when your application is running under the debugger, the working directory is not the project's directory, but rather the debugger's directory (or some other arbitrary directory that does not contain your DLL file).

Check (and fix) this by opening up your project's Properties and inspecting the Debugging settings. Specifically, Properties → Configuration Properties → Debugging. The "Working Directory" setting should be set to $(TargetDir).

2012-04-05 03:00
by Cody Gray
Nice catch. The value was set to $(ProjectDir - Steve Barna 2012-04-05 05:56
Ads