Jump to content
  • Advertisement
Sign in to follow this  
CProgrammer

dll current directory

This topic is 4064 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, Im trying to load a file within dll code. It seemed logical to me that opening it by specifying just the filename should open it in the same directory as the dll is in. Sadly this is not the case. Whats an elegant way to achieve this effect. Do I have to get the dlls path from its handle and then cut off the filename and add mine? Any better way? EDIT: Oh by the way this is in c++, windows with no stl. Thanks. -CProgrammer

Share this post


Link to post
Share on other sites
Advertisement
Just a guess: if you'r running from the debugger the current directory won't be the output directory (Debug or Release) but the one that contains your project file (usually one directory level lower).

Share this post


Link to post
Share on other sites
Hmm well im not starting it from the compiler. However reading your post reminded me that since this project is built ontop of someone elses code the active dircetory could be anything.
However is there a command to get the directory of the current process which should be the dll I made?

Share this post


Link to post
Share on other sites
The current directory is the same process-wide. It doesn't matter if you're in a DLL or not. So basically yeah, you need to get the path to your DLL (GetModuleFilename will give this to you) and mangle it yourself.

Share this post


Link to post
Share on other sites
You can get the active directory using GetCurrentDirectory.

If you want the path in which a module resides, use GetModuleFileName with a handle to the module. This will return the full path and file-name of the module. You can get the module handle by passing the unqualified module name (e.g. "plugin.dll") to GetModuleHandle. If you pass NULL to GetModuleFileName, it will return the directory of the executable file from which the process was spawned.

Admiral

Share this post


Link to post
Share on other sites
Hi guys,

thanks for the replys. Well having no choice I obtained the file path to the dll and edited it using memcpy and a while statement. Not the prettiest but it'll do :)

Thanks.

-CProgrammer

Share this post


Link to post
Share on other sites
Once you've got the full path to the module (GetModuleFileName), you can use PathFindFileName to get a pointer to the filename part of the path. Stick a null character there to get rid of the filename part and be left with the directory only. Then use PathCombine to combine the directory with the name of the file you're trying to open.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!