DLL - confuuuuuses!!

Started by
7 comments, last by the Chef 21 years, 7 months ago
I have 3 questions that REALLY confuses me. Please help! 1) Why link to a .lib file when the program uses a dll? Is it cause the lib file tells the compiler where to find the funcions adresses? 2) If so, how can I add a plugin via a dll-file? 3) What functions shall I use to put functions/data/etc in a dll-file? Thanks for all answers!
No way! I will never write a profile signature! :p
Advertisement
I think you should look at this link as it has some great tutorials on dll''s.

http://www.mindcracker.com/mindcracker/c_cafe/dll.asp
1- Using a lib file is called internal linking, which doesn''t require you to load the DLL yourself. If you don''t link it internally you''d have to load the DLL yourself using LoadLibrary() and then free it yourself using FreeLibrary()

2- You have to be more specific here. What program do you want to add a plugin for?

Here is an example of how to write a plugin for winamp with full source code.

3- The same way you do it in your program since DLL''s are nothing more than a program that can be loaded at runtime.

Hope this helps!

-G|aD-
Using a lib file in import fixup info into an exe is also called "static" linking - in contrast to using LoadLibrary/GetProcAddress which is called "dynamic" linking.

Chef, you might not be aware of it, but you use static linking every time you call an API function - CreateWindowEx, for example, is exported from User32.dll (CreateWindow is merely a macro wrapping CreateWindowEx).

A couple other urls related to plugins:

Plug-in Architecture Framework for Beginners
Plug-In framework using DLLs - DLLs
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Thanks for all posts, I understand a bit more - but not all I should..

If a dll means dynamic linked library, would it not be dynamic then? I read a siiiiimple tutorial about the dll''s, where I used a static .lib-library to get the functions inside the dll-file.

If the .lib-file tells the program where to find the functions, how can I then add models, plugins and similaiar to a program/game via a dll? There is no .lib file to tell any adresses this time, only a dll in a folder (put there by the user)... :/

Once again, thanx for all help!

The above post is mine... I had some problems posting it

[edited by - the Chef on September 12, 2002 11:20:49 AM]
No way! I will never write a profile signature! :p
quote:Original post by Anonymous Poster
If a dll means dynamic linked library, would it not be dynamic then? I read a siiiiimple tutorial about the dll''s, where I used a static .lib-library to get the functions inside the dll-file.

If the .lib-file tells the program where to find the functions, how can I then add models, plugins and similaiar to a program/game via a dll? There is no .lib file to tell any adresses this time, only a dll in a folder (put there by the user)... :/


There are two ways of using DLL files. You can dynamically link them using LoadLibrary, or you can statically link the .lib files that are created when you build a DLL Project.

If you want to have a program that loads plugins you''ll most likely want to use dynamic linking, that way you could make your program look for and load all plugins that it finds, meaning that others could add their own plugins.



Henrym
My Site
Plugins.

DLLs, as already described, can be used in two ways - static linking (handled automatically, and works like a .lib), and dynamic linking. You can use static linking if you have the library when you build the project - otherwise, you use dynamic linking.

A DLL, when built, has a number of ''exports.'' An export is a function or variable which is accessable from outside the DLL. Standard functions are exported by name - classes and so on can be exported too, but it''s a little more difficult.

You can dynamically load a DLL, and then get a pointer to one of the exported functions. LoadLibrary() will load the DLL, then GetProcAddress() will get the function pointer (which you cast into the correct type). When you''re done, you call FreeLibrary() to close the DLL.

That''s the best way to do Plugins. If you know the name of the DLL (say, from scanning the contents of the plugins folder), and you know the names of the functions you want (if you told people what to call them / export them as), then you can use dynamic linking to load/access the contents of the DLL.

There''s also a set of functions for accessing resources in a DLL, making them good for things like multiple languages (define all your strings in a string table, in a dll for each language).

Superpig
- saving pigs from untimely fates
- sleeps in a ham-mock at www.thebinaryrefinery.cjb.net

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Thanx for all answers! Now I understand
No way! I will never write a profile signature! :p

This topic is closed to new replies.

Advertisement