Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / How to specify the 'active program directory'?

Author
Message
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 19th Jul 2006 08:49
I have never been able to get the debug/relese exes to run properly, they always freak out in one way or another (sometimes they even cause my computer to reset!). I realized today its because (or at least partly because) the built exes cant find the media im trying to load. So something like...

dbLoadObject("cloudsobj.dbo",1);

...would look great if you ran the program from the compiler (vs 2003 in my case), but it wouldnt work at all if you tryed to run the debug or release exe thats created in the program directory. You have to specify the complete path...

dbLoadObject("C:\\Documents and Settings\\Jeff\\My Documents\\Visual Studio Projects\\blank\\cloudsobj.dbo",1);

...then everything works fine. Of course it wouldnt be possible to hardcode a path to all your media, since you dont know where stuff will be installed to.

So whats the proper way to handle this?

All you need is zeal
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 19th Jul 2006 09:51
After initializsation, use the dbSetDir function to specify a working directory. All media commands should access the specified folder when running.

Paul.


Home of the Cartography Shop - DarkBASIC Professional map importer
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 19th Jul 2006 10:15 Edited at: 19th Jul 2006 10:33
Ahhh yeah I was looking all over visual studio for some kind of project option, I shoulda known it would be related to db and not the compiler!

Thanks!

*Btw will this work for non db commands (like #include paths, ect...)?

*..wait.. How do I know what the 'active' directory is though? Arent there really two active directories in my example? The 'real' one, and the one that the debug/release exe is running out of?

All you need is zeal
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 19th Jul 2006 11:38
dbSetDir only works during runtime. #include paths are setup using the project properties, C++ include paths, and/or the tools/options project options.

To get the current working folder, use dbGetDir

Paul.


Home of the Cartography Shop - DarkBASIC Professional map importer
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 19th Jul 2006 12:55 Edited at: 19th Jul 2006 12:56
But when im running the release/debug exe, wont dbGetDir just point me to the release/debug folder (since thats the 'current' directory)?

Also how do you change the '#include root' on a per cpp bases?

Lets say I had a cpp file nested in a sub folder. Now lets say I want to include a file thats at the root of my PROJECT folder (up/back on level). How would you do this? Ive been using absolute paths all this time, and its a pain in the ass!

All you need is zeal
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 19th Jul 2006 13:09
Setdir would be based off where the executable is run from, which wont always be the release/debug folder.

Eg,

if your running an exe from the NicholasIsGreat directory
dbSetDir("Graphics")

would set the current working directory to NicholasIsGreat\Graphics

But if you ran the code from Windows, it would be Windows\Graphics

You would never hard code a path, so :

dbSetDir("c:\\nono") is a big no-no, and we would be around your house, quicker than Superman could fly if you did that, to teach you the error of your ways...

Come to the last Unofficial DBPro Convention (http://convention.logicstudios.net/)
Dont do anything I wouldn't do. But if you do, take pictures.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Jul 2006 13:17
Actually, the compiler can do this for you. I use 2003, so you may need to adapt this to your compiler of choice.

Right-click on your project in the Solution explorer, and select 'Properties' from the context menu. Click on the 'Debugging' item in the list pane, and you'll see a 'Working Directory' item in the right ...

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 19th Jul 2006 13:47
Cool that should solve the debugger directory issue (I use 2003 too), but what about my #include question? How do you point a nested cpp file to a header file that could be in the root project folder?

All you need is zeal
Barnski
18
Years of Service
User Offline
Joined: 26th Jan 2006
Location: Switzerland, Zurich
Posted: 19th Jul 2006 20:37
do you know the notion of relative paths?

"./" is the current directory
"../" is the parent directory

if you have an absolute path of: C:\mygame\bin\my.exe

then "../media/my.png" will denote a file in: C:\mygame\media\my.png

oh and you can use \ or /, it doesnt matter anymore under windows.
with / you only need one. and it is compatible with unix & linux.

when running your program from your IDE, the current directory will be the project file directory (not the debug or release folder in it, where the exe is compiled).
So you best just move the exe to the project folder if you want to test it outside of the IDE.

To let your cpp files find their includes, you can add the folders where your headers are located to your project settings.
another way would be to use the relative notion when declaring the include file: #include "../myheader.h"
furthermore there is a slight difference between using #include "some.h" and #include <some.h>
the difference is that with "" it will search in the project and cpp file folder, and the project include folders, while with <> it will search in any default include folder on the system, and your projects. But I am never too sure about this so I might be incorrect

CattleRustler
Retired Moderator
20
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Jul 2006 21:04
Quote: "I was looking all over visual studio for some kind of project option"


Application.StartupPath

returns the exe full path, regardless of debug/ide/external runtime
(2003)

Science, Mathematics, and Physics do not lie - only people do.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Jul 2006 21:21
Quote: "To let your cpp files find their includes, you can add the folders where your headers are located to your project settings"


That's the way I generally do it. I don't like using .. in my includes (personal preference - it works either way). In your project properties, select C++/General, and add the relative path to the 'Additional Include Directories' in the right pane.

For free Plug-ins and source code http://www.matrix1.demon.co.uk
CattleRustler
Retired Moderator
20
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 20th Jul 2006 00:05
ooh, didnt realize he is in c++

Science, Mathematics, and Physics do not lie - only people do.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 20th Jul 2006 09:14 Edited at: 20th Jul 2006 09:15
Cool thanks for all the tips, I finally got things sorted. The thing that really confused me was - dark sdks 'root path' seems to be the directory where your project file is. While the #include root is relative the the FILE (header or cpp) that youre working on.

In otherwords, the dark sdk root (used to load media) is ALWAYS the same (unless you use a command to change it), but the #include root is always changing.

Once I realized that things were pretty easy to manage

All you need is zeal

Login to post a reply

Server time is: 2024-05-25 09:40:26
Your offset time is: 2024-05-25 09:40:26