(The Unofficial) PopCap Framework Developer Board
September 24, 2017, 09:18:41 PM CEST *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
  Home   Forum   Help Calendar Contact Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Visual Studio and Debug Working Directory  (Read 41179 times)
0 Members and 2 Guests are viewing this topic.
silentsalamander
Guest
« on: June 17, 2005, 05:40:37 PM CEST »

Hello

So, I'm developing a project with the framework, but I have a problem: the working directories for the project always default to wherever the executable is. Therefore, for each of my build directories I have to place my resource directory directly beneath it (e.g. Debug, Release, etc.) If I update a resource, I have to remember to update it in every build subdirectory, which is a pain.

I pointed the project working directory ( Properties > Configuration Properties > Debugging > Working Directory ) to the actual project directory, but the behavior is the same. Does anyone know what I'm doing wrong?

Thanks
Logged
immortal3k
Guest
« Reply #1 on: June 17, 2005, 05:58:12 PM CEST »

Hi

Create "bin" directory and place there game resources
In Visual Studio open Project->Settings->AllConfiguration
Executable for debug session - bin\YourProgramm.exe
Working directory - bin
Output  file name - bin\YourProgramm.exe

ThatÂ’s all Smiley

BondarchukV
http://www.bondarchukv.com/
Logged
ace
Guest
« Reply #2 on: June 17, 2005, 06:35:32 PM CEST »

To override this changedir behavior you can put a ChangeDirHook in your App class like this:

Code:

bool MyApp::ChangeDirHook()
{
  return true;  // Derived app handles changing directories
}


What I normally do, though, is I just set the output directory of my project to .

Also I name the debug version name_debug.exe by setting the OutputFile in the linker/general project settings.  This way the debug version doesn't overrwrite the release version.
Logged
silentsalamander
Guest
« Reply #3 on: June 22, 2005, 06:39:06 PM CEST »

I tried ace's solution, and it worked great. I prefer to separate the different build object/exe output directories, so it was the ideal solution for me. To recap, in the application implementation:

Code:

bool Application::ChangeDirHook( const char *theIntendedPath ) {
return true;
}


...and header:

Code:

class Application {
.
.
.
   virtual bool ChangeDirHook( const char *theIntendedPath );
};


Thanks for the help!
Logged
DmitryShm
Guest
« Reply #4 on: October 22, 2008, 03:53:00 PM CEST »

Consider the following code

Code:

#ifndef WINVER                  
#define WINVER 0x0500          
#endif

#ifndef _WIN32_WINNT            
#define _WIN32_WINNT 0x0500    
#endif

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
#include
#include

#include
#include
#include

#include

void CheckFileOperation()
{
FILE * f;
errno_t err = _tfopen_s(&f, _T("file.txt"), _T("r"));
assert(err != ENOENT);
fclose(f);
}

class App : public Sexy::SexyAppBase
{
public:
App() : Sexy::SexyAppBase()
{
this->mVSyncUpdates = true;
this->mWidth = 1024;
this->mHeight = 768;
this->mNoSoundNeeded = true;
this->mIsWindowed = true;
this->mFullscreenBits = 32;
this->mAutoEnable3D = true;
this->mTitle = _T("chdir test");
}
void App::Init()
{
CheckFileOperation(); // 2
Sexy::SexyAppBase::Init();
CheckFileOperation(); // 3
}
};

int APIENTRY _tWinMain(HINSTANCE hInstance , HINSTANCE, LPTSTR, int)
{
CheckFileOperation(); // 1
             Sexy::gHInstance = hInstance;
App a;
a.Init();
a.Start();
return TRUE;
}


The file operation marked by 3 produces assertion because Sexy::SexyAppBase::Init() changes working directory without restoring the original one. Debugging in Visual Studio is the case when working directory differs from the one where executable is. It's framework's fault. User always can change working directory as it was said but it will be better not to force users always do it.
« Last Edit: October 22, 2008, 03:54:09 PM CEST by DmitryShm » Logged
David
Guest
« Reply #5 on: October 23, 2008, 03:11:35 AM CEST »

You can override the ChangeDirHook method to change the behavior, or use the -changedir command line parameter to override the behavior.
Logged
DmitryShm
Guest
« Reply #6 on: October 23, 2008, 01:05:00 PM CEST »

E.g. "Dear users, you can override the strange behaviour of our library that is set by default". I'd like to ask you whether it's so important to change the working directory without restoring the original one. I think it would be better to change this strange behaviour. And if this behavior is so important to you I'd like to ask in what ways it is so important. =)
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!
SimplePortal 2.3.3 © 2008-2010, SimplePortal