CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2009
    Posts
    1

    General Help please...

    Hi.

    I'm a newbie to C++ after having programmed with Java daily for 5-6 years. I've been trawling the web for a couple of answers to what should be some simple questions. Would anyone be able to either answer or point me in the direction of some sites with the solutions as googling hasn't really helped.

    1 - If i have a dll with a simple add method in it within a class called Adder. I take it I need to header file for this interface and the dll? In java you would just need the jar with the class in it
    but I take in this is the equivilent of the dll in C++.

    2 - Whats the difference between a dll and a lib?

    3 - Whats the difference between using LoadLibrary in the code and just referencing the dll in visual studio for example?

    Sorry is these are basic questions

    Thanks

    Richard

  2. #2
    Join Date
    Oct 2009
    Posts
    13

    Re: General Help please...

    2. one is a dynamic library and one is a static library

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: General Help please...

    1) it depends. At the very least, you will need to know the proper function prototype so you can call the function witht he right parameters and with the right return type using the right calling convention.
    If it's a regular DLL exporting undecorated names, all you need is the DLL and a definition of the function prototype so you can call it properly.

    If it's an MFC extention DLL, or a DLL exporting decorated names, you will typically need the headers and the .lib file with the DLL stubs.

    Just because you have the dll, and know one of the functions it exports, doesn't guarantee you can just call that one function and be done with it.

    You really need documentation of the DLL publisher to make sure of what you can and can't do. Without said documentation you're basically trying to find your way out of a big room while blindfolded.

    2) a DLL is an executable image containing functions/data/resources/... that is loaded at runtime. The DLL needs to be installed on any PC you want to run the exe.
    A Lib is an binary image containing functions/data/resources/... that is linked into your executable image. This lib does not need to be installed anywhere you want to run the exe as the necessary code from the lib has been linked 'inside' the exe.

    3) LoadLibrary is what's called as dynamic late binding. Whereas using a .lib to import a DLL is called 'early dynamic binding'. Extending on 2), importing a lib of functions is called static binding.
    The difference: Early binding via a lib, hardwires your exe to the DLL. When the exe is launched, the necessary dll is located and loaded alongside your exe. If the dll is missing or one of the functions you're binding to isn't in the dll, the exe will fail to start.

    Late binding allows you to make an exe that links to a DLL while allowing you to degrade if said DLL isn't available. This is sometimes necessary if you want to make use of new windows functionality, but also want to have your exe run on an older version of windows where that functionality wasn't yet available. When running on said older windows the menu option could be disabled or worked around somehow.
    It's also handy in case you have a LOT of dlls you could potentially load, but only need some of them occasionally. The loadLibrary solution then allows you to load the DLL only when it's needed thus reducing the memory and time overhead from loading it always at startup. There's specific support for this in the delayload feature of the VC++ compiler.

  4. #4
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: General Help please...

    Quote Originally Posted by Ballchain View Post
    2. one is a dynamic library and one is a static library
    Not entirely true. A DLL project generally generates a small .LIB file, and the same .LIB file can be used as linker input for other project (EXE or DLL type). Here the .LIB acts like 'Header-file'.

    When you create a Library project, the LIB file (of big size), is actually static-library. In this case, no DLL is required at runtime. The linker just puts in the whole library into final executable (or the DLL). The binary generated would, however, be large.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured