Steve Barna
Steve Barna

Reputation: 1388

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

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

Upvotes: 1

Views: 127

Answers (1)

Cody Gray
Cody Gray

Reputation: 244971

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

Upvotes: 1

Related Questions