Skip to main content
gamedev.net
🔒 Locked

multiple linked dll's

Started by thecrow21 3 replies 850+ views
Original Post
thecrow21
thecrow21
hello all! I have a few rendering functions in a DLL called 'engine.dll'. I use that dll with implicit linking (using a .lib file and dllimport) with my main application called 'application.exe'. Suppose that I want my application to be extendable, thus I want to add functions with explicit linking to a dll called 'extension.dll'. If I want the extension function to render output using the engine, how will I do it? Will I implicitly link the 'extension.dll' to the 'engine.dll', as with 'application.exe'? Won't that cause multiple definitions? The BIBLE(*) says that you can declare a function as many times as you want, but you can only define it once. I am a little confused... (*) also known as 'The C++ Programming Language' by Bjarne Stroustroup.
Drew_Benton
Drew_Benton
Quote:
Original post by thecrow21
Won't that cause multiple definitions? The BIBLE(*) says that you can declare a function as many times as you want, but you can only define it once. I am a little confused...

(*) also known as 'The C++ Programming Language' by Bjarne Stroustroup.


I think that is saying that you can prototype something as much as you want - but only define it once. For example, imagine you had 12 .cpp files that used a function:

void Draw();

Basically you could make the prototype for it in each .cpp file - so they can use it, but have it only defined once (as in make the entire function and its body ) in one .cpp file. *I think* that is what that is talking about - basically the header file concept of defining as much - but only have one implementation.
thecrow21
thecrow21
yes, i understand how it goes with cpp's and headers. what about dll's and executables. if one dll uses another, and they are both used by an executable, won't that break the one-definition rule?
Drew_Benton
Drew_Benton
Quote:
Original post by thecrow21
yes, i understand how it goes with cpp's and headers. what about dll's and executables. if one dll uses another, and they are both used by an executable, won't that break the one-definition rule?


Ahh I see, sorry. Yes, If one .dll uses some function it defines, void Draw(), and a second .dll uses some function it defines, void Draw(), there will be a collision and it will not work right. To get past this you have three choices - 1. use one .dll or the other, 2. Rename functions, or the most reasonable, 3. Use namespaces. That way, you can use something like DLL1::Draw() or DLL2::Drraw() to get past the name collision.
BeanDog
BeanDog
I think that what you're getting at is that you want to load DLL's dynamically, like a plug-in. Fortunately, C++ and the Windows SDK have some great features set up to help with this.

Using the LoadLibrary function you can retrieve a handle to a DLL by passing the function a filename. You use FreeLibrary to unload the DLL when you're done using it (at program termination, usually). Then, you can pass that DLL handle to GetProcAddress to retrieve a pointer to the function in the DLL, which you can then call like any other function pointer. And since the DLLs' functions are never loaded into program memory in the same way your executable is, it is impossible to have namespace conflicts in this way. That is, you can load 100 DLLs with a function 'foo' in them, because you are simply keeping a function pointer, not calling a normal function by name. (*(pFoo[43]))(); instead of foo();.

A note for the uninitiated: Make sure you compile your DLL so that the function names aren't mangled. If you try to use GetProcAddress and can't seem to get it to work, that's probably your problem. I think MSVS6 comes with a tool to view all the function names in a DLL as you would pass them to GetProcAddress, and you can use that to check your work.

I was going to include an example from MSDN, but it seems that the "copy and paste" functions on this old dude's spyware-infected PC doesn't work. Search MSDN online and you should be able to find ample examples of this type of functionality.

Hope this helps!



~BenDilts( void );
PS Sorry for not including code or links. I didn't realize how hard it is to work without Copy and Paste! Argh!

[Edited by - BeanDog on January 13, 2005 9:32:04 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.