Thread: How would you link a program to a DLL?

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, the main difference is that dynamic linking allows you load an unload dlls at any time. It also allows you to dynamically specify which dlls to load, as opposed to implicit linking. Dynamic linking will also allow to ignore if a dll fails to load or provide your own custom error messages.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Oh I see bithub just called it explicit. However, according to MSDN, it's called implicit linking.
    But even so, the name doesn't really mean that much. It's the first method I mentioned, using a .lib file.
    Where does it say that? By calling LoadLibrary() you are explicitly linking to the DLL file. By using a .lib file with no LoadLibrary() call, you are implicitly linking to the DLL file. I'd like to see where MSDN says otherwise. Especially considering they make it very clear right here.

  3. #18
    Emulator
    Join Date
    Feb 2008
    Posts
    43
    :S This is getting a little confusing. Oh well, would you really need to know the difference when all you're trying to do is link a DLL to a program?

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    http://msdn2.microsoft.com/en-us/library/d14wsce5.aspx
    Implicit linking is using a .lib file. Explicit linking, aka dynamic linking, is using LoadLibrary and GetProcAddress.

    Quote Originally Posted by PЯO View Post
    :S This is getting a little confusing. Oh well, would you really need to know the difference when all you're trying to do is link a DLL to a program?
    You should. But most times you only need to use implicit linking (.lib file).
    Dynamic linking might be useful if you need to, for example, load all dlls in a certain directory (for example, plugins).

    Well, actually, the link states that there are two methods:
    Implicit linking (also known as static linking or load-time linking)
    and
    Explicit linking (also known as dynamic linking).
    Last edited by Elysia; 02-09-2008 at 04:37 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Emulator
    Join Date
    Feb 2008
    Posts
    43

    Talking

    Quote Originally Posted by Elysia View Post
    http://msdn2.microsoft.com/en-us/library/d14wsce5.aspx
    Implicit linking is using a .lib file. Explicit linking, aka dynamic linking, is using LoadLibrary and GetProcAddress.


    You should. But most times you only need to use implicit linking (.lib file).
    Dynamic linking might be useful if you need to, for example, load all dlls in a certain directory (for example, plugins).
    When you are doing implicit linking, what is the .lib file needed for?

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It does an automatic GetProcAddress for you, to put it simply. So the function calls are made correctly.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Emulator
    Join Date
    Feb 2008
    Posts
    43
    Do the .lib files come with the compiler? Because I think I know what you're talking about.

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, they typically do for dll files for the C++ standard libraries (and C too).
    You'll also find them in SDKs such as Windows SDK to link statically with Windows DLLs (such as winmm.dll).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Well, actually, the link states that there are two methods:
    Implicit linking (also known as static linking or load-time linking)
    and
    Explicit linking (also known as dynamic linking).
    No, they are sometimes called static or dynamic loading. Once again, if it is a DLL file then it is always dynamic linking.

  10. #25
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by bithub View Post
    No, they are sometimes called static or dynamic loading. Once again, if it is a DLL file then it is always dynamic linking.
    Implicit linking is sometimes referred to as static load or load-time dynamic linking. Explicit linking is sometimes referred to as dynamic load or run-time dynamic linking.
    Where does it say that it's always dynamic linking when it's dlls? Your link certainly doesn't mention.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Where does it say that it's always dynamic linking when it's dlls? Your link certainly doesn't mention.
    It's always a dynamic link with DLL files because the link is always done at runtime. A static link is done at compile time (these are done with .a files, not .dll files). Hense the name Dynamic Link Library.

  12. #27
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    There is such method as delay-load dlls

    you link dll using lib-file,
    you do not need to use LoadLibrary and GetProcAddress functions
    but you can check if the library is available - and if not - your application still can be loaded without showing this nice windows message "File not found" and work successfully, just not calling any function from dll
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  13. #28
    Emulator
    Join Date
    Feb 2008
    Posts
    43
    Can someone give me an example of both the DLL, and the program itself? Thank you.
    Hand over your source code, and nobody gets hurt.

  14. #29
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why don't you do the DLL and ask for help in making the application use it, if you can't figure it out yourself?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. How to link dll
    By liang in forum Windows Programming
    Replies: 5
    Last Post: 07-14-2005, 11:55 PM
  3. dynamically link my DLL to an application
    By Maranello in forum C++ Programming
    Replies: 0
    Last Post: 04-20-2005, 07:52 AM
  4. DLL Error with VB .NET Program
    By willc0de4food in forum Windows Programming
    Replies: 6
    Last Post: 04-09-2005, 02:38 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM