|
-
July 12th, 2007, 09:41 PM
#1
problem with tinyxml in visual c++
hi
I was programming with dev c++ for a while.
I decided to move everything to visual studio for a reason.
Here is the problem I have
1. when launch the executable in visual studio - using start without debugger or with debugger - the application says it can't find QnA.xml - an XML file used in my application in the Question.cpp file.
But when I launch the executable outside the visual studio environment - (by double-clicking the executable) the executable starts up fine and finds the QnA.xml file.
Here's the code in my question.cpp file.
Code:
void initialize(bool bisOrdered)
{
isOrdered = bisOrdered;
TiXmlDocument doc( "QnA.xml");
bool loadOkay = doc.LoadFile();
bool firstQuestion = false;
if( !loadOkay )
{
MessageBox( NULL, "Can't load QnA.xml", "Error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL ) ;
}
// ... etc.
}
When I start up the application, inside visual studio I see the messagebox.
When I start up the application outside visual studio I don't see the message box it appears everything loads just fine.
These problems never existed when I was using Dev C++
Any thoughts ?
Stephen
I don't know if this is a clue but I am also posting on another problem upon shutting down in another thread.
-
July 12th, 2007, 10:01 PM
#2
Re: problem with tinyxml in visual c++
i had a problem similar to yours when i was learning some SDl and trying to load my programs from within the environment it wasnt able to locate any of my bitmaps but worked just fine when i did it from explorer, would be nice if someone could explain whats going on =]
-
July 13th, 2007, 07:38 AM
#3
Re: problem with tinyxml in visual c++
One thing to keep in mind is that the way Visual Studio launches one of your programs is different than the way Explorer does it. Explorer passes the new process the path that your see in the Explorer tree, but VS passes it a path that usually starts in the executable node, and so when you hand the process a line like:
TiXmlDocument doc( "QnA.xml");
the process can't find the file in the current executable directory and you get an error.
You might have set up your program's environment like this:
C:\Program Files\MyApp\MyExe.exe
C:\Program Files\MyApp\QnA.xml
So, both files are in the same directory.
Visual Studio does this:
C:\Program Files\Projects\MyAppsCode\Release\MyExe.exe
If you put 'QnA.xml' in
C:\Program Files\Projects\MyAppsCode\,
then you will get an error because your executable is executing out of
C:\Program Files\Projects\MyAppsCode\Release\.
There are several ways to fix this. One resolution, of course, is to move (or copy) the file into the correct directory, or better, add some code to figure out where the file is located in relationship to your executable so you don't have this problem.
You might want to do an '#ifdef ..." switch on the data path for different environments: production release, testing, etc.
-
July 13th, 2007, 07:49 AM
#4
Re: problem with tinyxml in visual c++
You can change the output of your project (property pages -> linker -> output file) to your directory (application directory);
and the working directory (property pates -> debugging-> working directory) to your application directory.
-
July 13th, 2007, 11:29 AM
#5
Re: problem with tinyxml in visual c++
If you include the files (xml, txt) into your project (via 'add existing item'), you can then set it so the build process automatically copies the file to the output folder. To set this, just select the file in the solution explorer, right click and choose 'properties'. From there change the 'Copy to Output Directory to either 'Copy always' or 'Copy if newer'.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|