Thread: Dynamic Linking Library questions

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Question Dynamic Linking Library questions

    (This is probably in the wrong section, I'm not totaly sure what DLL's are in reguard to, hence the post)

    Hey, I'm wondering if anyone would mind answering a few questions about .DLL files.

    First off, I see DLLs used in lots of application, and I'm assuming they aren't unique to C++. Which would lead me to ask, how would you compile to a DLL? And also, is there any specific language for DLLs?

    What are DLLs used for?

    And last off, DLLs pop up all the time on older applications, but in newer ones I seldom see them. Why would you/woulden't you use dlls?

    Well thanks for your help, and sorry if this isin't in the right forum section.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm pretty sure this should be moved to another forum, yes. I'm sure one of the moderators will move it to the relevant section.

    DLL stands for Dynamic Linked Library.

    Since none of us would like to write ALL teh code needed to run our applications, we often use library code to make life easier - this is anything from the basic IO functions (such as cin/cout in C++) to for example Windows MFC windowing functions, complex math libraries to solve matrix calculations or database access libraries, just to give a few examples.

    In the old time, a library was just a collection of object files packed into a single file, and the linker would pick object files from the library file when linking. The problem with this is that EVERY application now contains a copy of the functions it uses - in classic C that would be printf, scanf, and such things, or the methods for cin, cout in C++.

    So someone came up with the idea of sharing these things, so instead of linking in at the time of application is built, we link in the object code dynamically when the application starts. This is done by "the loader", that is the part of the OS that loads the executable file.

    Each DLL is only loaded once, and then shared between different applications. That way, we only need ONE copy of each function that is needed by many different applicaitons, and we don't need to have such huge applications any longer.

    So the main reason for using DLL's is to share the code between different applications, either to reduce the memory foot-print, or if a software produce consists of several executables that have a common base of code, one could put all that common code in a DLL and let each executable use the DLL - this way, you end up with smaller executable files, and less code to distribute.

    There is a third reason to use DLL's and that is a development model reason: If we have a large software product, we can separate the product into several smaller components, each of which may be made into a DLL. That way, you could produce some of those sub-components independently, making the portions of resulting code more managable. [You can build a small application that links to the DLL for test purposes, without needing the FULL application to be complete before it can be tested, for example].

    So, there's several reasons to use DLL's, as you can see. Almost any application you use on Windows will use at least a few DLL's.

    As how you produce a DLL, most IDE (Integrated Developer Environment) have a project setting that allows you to say "make this a DLL". If you tell us what IDE you are using, I'm sure someone is familiar with that.

    However, there are other things you need to do to make a DLL, and it can get quite complex if you want to use C++ with DLL's. I'm afraid, I can't really explain all of those complexities.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    The manual also sums up what matsp said pretty good, http://gcc.gnu.org/onlinedocs/gcc-3....DLLs_0029.html
    It also covers exactly how a DLL works compared to a statically linked library, that calls are slower etc (because they're indirect).

    >And also, is there any specific language for DLLs?
    Yes, take visual basic for example. You can't use VB6 dlls in your C programs, but you can use C dlls in your vb programs (So I believe). It holds especially true with < VB3 which ran on a virtual machine - although I think VB still does...
    Last edited by zacs7; 10-10-2007 at 03:25 AM.

  4. #4
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Very comprehensive responses, thanks! That was everything I needed to know .
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You can use VB6 DLLs in C. It's just very tedious. You have to obtain an IDispatch interface pointer, look up method IDs on it and then call through it. Don't forget to wrap all your arguments in VARIANTs, and unwrap the result.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-29-2009, 06:42 AM
  2. shared library, but not dynamic !?
    By ccox421 in forum C Programming
    Replies: 11
    Last Post: 03-17-2009, 01:03 PM
  3. Linker errors in VC++ 2005
    By C+/- in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2007, 07:42 AM
  4. Need help with audio library on DOS...
    By Marton79 in forum C Programming
    Replies: 10
    Last Post: 08-25-2006, 12:32 AM
  5. Library Linking problem
    By Lynchie in forum C Programming
    Replies: 3
    Last Post: 07-23-2002, 08:49 AM