Jump to content

Arbitrary Locations for DLL's


tiridor
 Share

Recommended Posts

Sorry in advance if this has been answered before, but a quick search didn't result in anything quite like my question.

 

(using C) I've been all over the place trying to figure out how to have all of my DLL's outside of the main executable directory and came to the conclusions that I would either have to run the implib tool to import .lib files into my app or use the LoadLibrary/GetProcAddress for every engine function to make it work. Just when I was about to give up, I ran a build and successful run that according to everything I was reading, shouldn't work.

 

#include "engine.h"
int main (int argc, char** argv)
{
   LoadLibrary(L"lib\\engine.dll"); //relative path
   LoadLibrary(L"lib\\newton.dll");
   Initialize();
   Graphics(640, 480, 0, 0, GRAPHICS_BACKBUFFER+GRAPHICS_DEPTHBUFFER);
   ...
}

 

**engine.cpp is also added to the project, of course

 

These two LoadLibrary lines allow me to place the dll's anywhere I want outside of the executable (and system directories) and gives me full access to all of the core engine functions without redefining and fiddling with function pointers. My question is why does this work? Is it because Josh handles the GetProcAddress calls in "engine.h" through the cryptic defines? Maybe I just answered my own question, but I was just hoping for a response from someone who's more experienced with runtime dll loading than me.

Link to comment
Share on other sites

True, that was my first thought but I don't necessarily want to mess with a customer's system environment for a game. This way, I get the best of both worlds. I don't have to change any core files and I don't have to mess with system wide settings. yes/no, or am I missing something that should be obvious? It certainly wouldn't be the first time smile.png

Link to comment
Share on other sites

Put your game.exe in a bin subfolder, and the dlls also. Then make a simple launcher exe in the main folder, which does a chdir("bin") and then starts the game using system("game.exe") or WinExec("game.exe").

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Thanks Roland & Metatron,

 

I appreciate the advice but I think I'll stick to my current method wink.png I like the idea of having my dll's in a separate directory that I can change at anytime even through a config file after install if I felt so inclined (not that i would smile.png )

 

My interest was primarily in the 'why does this work?' aspect when it shouldn't without GetProcAddress calls all over the place. Anyway, it looks like it was a stupid question now that I have spent more time looking at the engine header. Sorry for posting without digging deeper for the answer myself.

Link to comment
Share on other sites

I don't necessarily want to mess with a customer's system environment for a game. This way, I get the best of both worlds. I don't have to change any core files and I don't have to mess with system wide settings.

Exactly, this is interesting. Thanks for posting tiridor.

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...