Moving DLL's

Get answers to all your basic programming questions. No Ogre questions, please!
User avatar
Emmeran
Goblin
Posts: 272
Joined: Wed Jun 02, 2004 11:47 am
Location: Erlangen

Moving DLL's

Post by Emmeran »

Hi there,
I have about 20 .dll-files in my output directory now and I would love to put them in a subdirectory called DLL. Is it anyhow possible, to move all DLLs needed by my application into a subdirectory? If yes: how? *g*

Thx in advance,
Emmeran
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8

Post by haffax »

I know there were some posts on this topic and one quite complete with all options, but I can't find it.

Having your executable in one directory and all other DLLs in another directory difficult to archieve, because of the way DLLs are loaded. There are basically two ways: you use an import lib for the DLL (like Ogremain.lib is for OgreMain.dll) or you load your library dynamically via LoadLibrary()(or similiar don't know the true API call). This is done with the plugins.

For the first option the DLL must be found by the system. It searches for it in some places, namely the current working directory and your system32 directory. So if you don't want to have your DLLs littering your directory you could place them into system32. But this absolutely cries for problems.

Another way is to have an executable, that does some initialization work, whatever your application has to do then changes the working directory to where the DLLs can be found and then dynamically loads your game dll, that is linked against OgreMain.lib et al. I've never done this, so there might be trouble I don't know of.

Or just start your application with a batch file that changes work directory to the directory with your executable and DLLs.
team-pantheon programmer
creators of Rastullahs Lockenpracht
iq
Greenskin
Posts: 125
Joined: Mon Oct 20, 2003 8:25 pm

Post by iq »

I think the search path is searched too, so you could add add the dll directory to the path.

but your best bet is a launcher app/bat file that calls the main exe inside the dll folder.
User avatar
Emmeran
Goblin
Posts: 272
Joined: Wed Jun 02, 2004 11:47 am
Location: Erlangen

Post by Emmeran »

I don't want to change anything in the system, namely copying files to system directory. And I don't want to use batch files.
So I think the only way will be to try LoadLibrary() because if I change the env vars inside the application it's too late.

Thx for your answers,
Emmeran
alphabeta
Kobold
Posts: 34
Joined: Mon Jan 03, 2005 5:07 am

Post by alphabeta »

http://www.codeguru.com/Cpp/W-P/dll/article.php/c99
This shows a way to use application specific dll paths in windows, but take a step back and make sure you really want to do this first. It's not portable, and you have to go through the registry. A better idea would be keeping the exe with the dll's, and using a shortcut (or batch file) to the exe in the root folder of your app.
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

I also think the solution with building your entire application as DLL and then making a stub that sets the current directory and then loads it with LoadLibrary (then starts the real run() function) is the best approach.
User avatar
Emmeran
Goblin
Posts: 272
Joined: Wed Jun 02, 2004 11:47 am
Location: Erlangen

Post by Emmeran »

that sounds great, thanks