Jump to content

Working Directory Changes


gamecreator
 Share

Recommended Posts

I have a program that detects the current working directory via

 

char* buffer;
buffer=_getcwd(NULL,0);
MessageBoxA(0,buffer,"Working Directory",0);

 

If I run the exe directly, it comes back with the directory it's in. However, if I drag a file onto it, even if it's from the same directory, buffer returns "C:\Documents and Settings\me"

 

This is troubling because the assets are loaded from a subdirectory and the program now can't find them. I'd like to use a file I drag onto the exe but I don't want the working directory changed from where the file really is. Any ideas?

Link to comment
Share on other sites

That's an interesting problem. I use getcwd but have never started the executable by dragging and dropping a file onto it.

 

You might try the WIN32 API GetModuleFileName() or GetModuleFileNameEx() functions.

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...