Jump to content
  • Advertisement
Sign in to follow this  
Tree Penguin

Loading a DLL at runtime?

This topic is 5081 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

Lets say you have a few versions of a dll and at startup you load the one that's listed in your configuration file. Is that possible? If not i guess it's possible in this more cumbersome manner: - The app loads (startapp) - startapp copies the right dll to the other executables' (the one that needs the dll) working directory - startapp starts the actuall main app Right? [Edited by - Tree Penguin on August 21, 2004 3:11:59 PM]

Share this post


Link to post
Share on other sites
Advertisement
Yes, you can load a dll from a configuration file and use that path to load the functions that you need.

Basically you just get the string containing the dll path and load it using the "LoadLibrary" function.

-TOmcAT

Share this post


Link to post
Share on other sites
You must remember that using LoadLibrary() requires you to search for identifiers yourself as opposed to having them link at startup. So for every function you want to call you will have to manually obtain the function pointer (see GetProcAddress()). (Otherwise you would have to use Self-Modifying Code, which is unfortunately not available).

Share this post


Link to post
Share on other sites
Quote:

- The app loads (startapp)
- startapp copies the right dll to the other executables' (the one that needs the dll) working directory
- startapp starts the actuall main app

A possible variation on this can be done using delay loading. Delay loading means that the DLLs your apps are linked against will not be loaded at startup, but rather at the first time a function from that DLL is used. MSVC++6 has support for this with some sort of /DELAYLOAD flag or something. Check with MSDN for more info.

What you'd do is switch delay loading on, and then do all the copying you describe in some initialization function in your application.

THat'd save you the pain of writing a startapp - just write a startup function. However, this isn't an elegant solution either.

Share this post


Link to post
Share on other sites
Linux uses .so (shared object) files and provides an API to load them which is almost the same as Windows.

dlopen() opens the .so, like LoadLibrary() on Windows,
dlsym() gets the functions you want from the .so, like GetProcAddress(),
dlclose() closes the .so, like FreeLibrary().

Share this post


Link to post
Share on other sites
Ok, i can't get it to work probably because of some stupid mistake i made (as usual).

I have this for function (pointer) definention: (i just give you one example)

// Some header file
typedef int (*GAMESTARTGAMEPROC) (void);
extern GAMESTARTGAMEPROC gameStartGame; //declared in a source file

// In the source file
gameStartGame=(GAMESTARTGAMEPROC)GetProcAddress(GameModule,"gameStartGame");


The library is loaded successfully, the function isn't, it stays NULL.

Error: 127: can't find the specified procedure. (if i translate it correctly)

// The function is declared in the dll's header file like this:

__declspec(dllexport) int gameStartGame(void);

[Edited by - Tree Penguin on August 21, 2004 1:21:25 PM]

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!