VC++ Directories Problem

Recommended Posts

Chacha    138
I have recently started using Microsoft Visual C++.net 2003 and am confused about project directories. This is the default project directory setup, with my extra 'Data' folder used to store project data such as graphics and sounds:
PROJECT
main project files...
DATA
texture files...
sound files...
DEBUG
app.exe
other files...
RELEASE
app.exe
other files...

(note that PROJECT, DATA, DEBUG AND RELEASE are all folders)


Ok, this seems nice and simple, but I've found a problem. When specifying directories in my code, such as a directory to a texture file which needs to be loaded, I don't know whether to give the directory relative to the project folder, or relative to the Debug and Release folders. When I run the application inside of the VC++ IDE, the application seems to use directories relative to the main project folder (so in this case I would use directories like "Data/whatever.bmp"). But when I get out of the IDE and run the application on its own, the application seems to use directories relative to where the application actually is (in this case, the application is in the Debug or Release folder), so I would need to specify directories such as "../Data/whatever.bmp". This is very annoying, and I don't know what to do. As an example to prove this problem exists, I wrote a little test program:
int main()
{
const char *file = "Data/test.txt";

ifstream fin(file);

if (!fin)

else
{
cout << "File found!\n";
fin.close();
}

cout << endl;

system("pause");
return 0;
}


When I run this app in the actual VC++ environment, the file can be found. But when I go into My Documents and run the app from the 'Release' or 'Debug' folder, the file cannot be found. There must be a way around this, any help is appreciated.

Share on other sites
vovansim    336
Hi,

Well, I think you pretty much figured it out. The resource paths are relative to where you are running the program from - namely, the debug / release folder. However, the IDE makes it look as if you are running the program from the project folder.

Now, I would suggest leaving the paths relative to the project folder, because otherwise, when you are done, you'd have to have in the final application a release folder containing the EXE, and that wouldn't be cool. :)

One way to work around this is simply copy the EXE from the debug / release directory into the project directort after the build, and so if you want to run it from there, you can do it without the IDE. You can also do it automatically.

In the Solution Explorer, right-click your project, then select "Properties". There, choose Build Events -> Post-Build Event. And there, under "Command Line", just type in a command to copy the binary from the build directory into your project directory:

copy $(OutDir)\$(TargetFileName) $(ProjectDir) An even easier way would be to output your binary straight to the project directory. To make it so, go to project properties again, and then on the "General" page, the very first item - Output Directory - set it to:$(ProjectDir)

Vovan

Share on other sites
iMalc    2466
Yeah, make it output straight to the project directory. That is what I have always done when I would otherwise have this problem. I'll even go out on a limb and say that it would be the preferred way to handle this.

Share on other sites
Chacha    138
Thanks a lot guys.

I have another question. How can I create a new project without VC++ creating a new folder for my project? For example, say I want to create a new project named 'NewProject', and I want it created in an existing directory such as "C:/...blahblah/myprojects", instead of it being created in "C:/...blahblah/myprojects/NewProject".

Share on other sites
Chacha    138
Does anybody know how to change this? I've been looking for an option to change this in the VC++ IDE, but I can't find anything.

Share on other sites
Verg    450
Quote:
 Original post by ChachaThanks a lot guys.I have another question. How can I create a new project without VC++ creating a new folder for my project? For example, say I want to create a new project named 'NewProject', and I want it created in an existing directory such as "C:/...blahblah/myprojects", instead of it being created in "C:/...blahblah/myprojects/NewProject".

Easy d00d:

File-->New

Click project tab
type the project name
erase the "directory" name appended in the box "Location:"

voila.

Share on other sites
Chacha    138
Quote:
 Original post by VergEasy d00d:File-->NewClick project tabselect "add to current workspace"choose your project typetype the project nameerase the "directory" name appended in the box "Location:"voila.

It doesn't work, there is no "add to current workspace" option (or perhaps I can't find it, but I'm sure that's not the case since I've looked EVERYWHERE). Remember I'm using MSVC++.net 2003.

Please, can somebody help me with this?

Share on other sites
Endurion    5411
In the big dialog that lets you choose the project type there are two radio buttons almost at the bottom. The left one's "add to workspace" the right one's "close workspace".

You can choose either, the first will add the new project to the current solution (workspace).

Share on other sites
Chacha    138
Quote:
 Original post by EndurionIn the big dialog that lets you choose the project type there are two radio buttons almost at the bottom. The left one's "add to workspace" the right one's "close workspace".You can choose either, the first will add the new project to the current solution (workspace).

No, I don't mean adding a new project to an existing workspace...what I'm asking is how to create a new workspace without a new folder named 'NewWorkspaceName' being created. Is this even possible?!

[Edited by - Chacha on August 6, 2004 12:44:53 AM]

Share on other sites
Chacha    138
I don't want to seem annoying, but I really want to figure this out. Does anybody know how?