none
Lib file and dll usage RRS feed

  • Question

  • Hi I am using method from calling from lib. Where it does store inside the project? What I know is only for dll file, I have to add reference. But for lib, I don't need any reference . Anyone please explain me how exactly that lib is working for that project? And what those two dll file is used for?

    Monday, September 11, 2017 6:30 AM

Answers

  • Hi _birdy,

    According to your description, you are a bit fuzzy on lib and dll, please see the following info.

    There are static libraries (LIB) and dynamic libraries (DLL).

    Libraries are used because you may have code that you want to use in many programs. For example if you write a function that counts the number of characters in a string, that function will be useful in lots of programs. Once you get that function working correctly you don't want to have to recompile the code every time you use it, so you put the executable code for that function in a library, and the linker can extract and insert the compiled code into your program. Static libraries are sometimes called 'archives' for this reason.

    Dynamic libraries take this one step further. It seems wasteful to have multiple copies of the library functions taking up space in each of the programs. Why can't they all share one copy of the function? This is what dynamic libraries are for. Rather then build the library code into your program when it is compiled, it can be mapped into  your program as it is loaded into memory to run. Multiple programs running at the same time that use the same functions can all share one copy, saving memory. In fact, you can load dynamic libraries only as needed, depending on the path through your code. No point in having the printer routines taking up memory if you aren't doing any printing. On the other hand, this means you have to have a copy of the dynamic library installed on every machine your program runs on. This creates its own set of problems.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by _birdy Tuesday, September 12, 2017 7:44 AM
    Tuesday, September 12, 2017 5:36 AM
    Moderator

All replies

  • Hi _birdy,

    According to your description, you are a bit fuzzy on lib and dll, please see the following info.

    There are static libraries (LIB) and dynamic libraries (DLL).

    Libraries are used because you may have code that you want to use in many programs. For example if you write a function that counts the number of characters in a string, that function will be useful in lots of programs. Once you get that function working correctly you don't want to have to recompile the code every time you use it, so you put the executable code for that function in a library, and the linker can extract and insert the compiled code into your program. Static libraries are sometimes called 'archives' for this reason.

    Dynamic libraries take this one step further. It seems wasteful to have multiple copies of the library functions taking up space in each of the programs. Why can't they all share one copy of the function? This is what dynamic libraries are for. Rather then build the library code into your program when it is compiled, it can be mapped into  your program as it is loaded into memory to run. Multiple programs running at the same time that use the same functions can all share one copy, saving memory. In fact, you can load dynamic libraries only as needed, depending on the path through your code. No point in having the printer routines taking up memory if you aren't doing any printing. On the other hand, this means you have to have a copy of the dynamic library installed on every machine your program runs on. This creates its own set of problems.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by _birdy Tuesday, September 12, 2017 7:44 AM
    Tuesday, September 12, 2017 5:36 AM
    Moderator
  • Thanks for the clear explanation. But I am still wondering is there any physical location where the Static Library file is stored inside .NET project. I am aware the DLL files are stored inside bin folder of the project(or) have to install in the Assembly folder of the machine which you are using that .NET project. Am I right? Please correct if there is a missing in my understanding?

    Thanks and Regards,

    _birdy


    • Edited by _birdy Wednesday, September 13, 2017 1:50 AM missing wording
    Wednesday, September 13, 2017 1:30 AM
  • Thanks for the clear explanation. But I am still wondering is there any physical location where the Static Library file is stored inside .NET project. I am aware the DLL files are stored inside bin folder of the project(or) have to install in the Assembly folder of the machine which you are using that .NET project. Am I right? Please correct if there is a missing in my understanding?

    Thanks and Regards,

    _birdy


    Hi _birdy,

    If you want to use method from calling function, what you need to do is:

    1. Write a simple wrapper DLL in C++ or C that exposes the functions in the LIB that you want to call from C#.
      You do that by writing a function for each LIB function you want to expose, and just call the LIB function from your function and return the result.
    2. Use P/Invoke to call functions in your wrapper DLL.

    I think the wrapper DLL is same with the DLL file in .NET project , they are all in the bin folder of the project, you could not call .lib file directly.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 19, 2017 6:24 AM
    Moderator