gamecreator Posted April 28, 2012 Share Posted April 28, 2012 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? Quote Link to comment Share on other sites More sharing options...
ParaToxic Posted April 28, 2012 Share Posted April 28, 2012 So you want both directory's when you drag on a file,from the file itself and the exe.? Quote Link to comment Share on other sites More sharing options...
Pixel Perfect Posted April 28, 2012 Share Posted April 28, 2012 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. Quote 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 More sharing options...
gamecreator Posted April 28, 2012 Author Share Posted April 28, 2012 I only need the directory the exe is in but I don't see a way to get it. But I'll try Pixel's suggestion. I'm hoping Josh sees this thread as he wrote a program or two that does this. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted April 28, 2012 Author Share Posted April 28, 2012 If anyone wants to play with it, I've uploaded the exe, cpp and Visual C++ Express Edition files here: http://www.mediafire.com/?b73k885hxs8sx9a Quote Link to comment Share on other sites More sharing options...
gamecreator Posted April 28, 2012 Author Share Posted April 28, 2012 I found the answer on another forum I posted on. Thank you both though. char s[MAX_PATH]; if (GetModuleFileNameA(NULL, s, sizeof(s) / sizeof(*s)) > 0) printf("GetModuleFileName=%sn",s); Quote Link to comment Share on other sites More sharing options...
Pixel Perfect Posted April 29, 2012 Share Posted April 29, 2012 Thats the same answer I gave (GetModuleFileNameA is just the ANSI version), but glad its working anyway Quote 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 More sharing options...
gamecreator Posted April 29, 2012 Author Share Posted April 29, 2012 You're right Pixel. Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.