CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2017
    Posts
    5

    Visual studio import library

    Is there any way to add external libraries files to project quick?

    Like I have used to do in java eclipse:
    Copy/Paste all jars to project folder, and with 2 extra clicks in project options I have added jars and I can work on. ( without creating libraries sections/paths/linkers etc...)

    Expecting similar way here, is it possible? Just copy dll files to project and use it?

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Visual studio import library

    Just copy dll files to project and use it?
    Yes and no. This depends upon how they are used within the c/c++ code. There are two ways to use .dll's.

    The first is that they are linked (either statically or dynamically) at compile time. This requires that a .lib file is present for each of the .dll files to be used. The .lib file is created when the .dll file is created. You specify to the compiler the location of the .lib files (if in a different location) and the name(s) of the import files to be used (either within the solution properties or as a #pragma statement in the program code).

    The second way is to use run-time dynamic linking. The program explicitly loads the .dll library into memory (LoadLibrary() https://msdn.microsoft.com/en-us/lib...v=vs.85).aspx) and explicitly obtains the memory address of the required exported function in the .dll (GetprocAddress() https://msdn.microsoft.com/en-us/lib...v=vs.85).aspx). In this way, a .lib file is not used but some extra code is needed in the program to load the library and get the required addresses etc. See https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx for an example of doing it this way.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Visual studio import library

    Quote Originally Posted by programm View Post
    Is there any way to add external libraries files to project quick?
    Actually it depends on your experience and your definition of quick. C/C++ is really different from Java/C# where the trick you described is possible because the language ecosystem was intentionally designed that way to ease importing foreign code bits. C/C++ coding not even close to rapid development concept (no matter what the subscript on the compiler box tells you), and there still is a certain level of competition on the compilers market that prevents cross-use of C++ dlls. C++ Builder produces C++ dlls that Visual C++ is unable to link to. Not question of speed, but ability itself.

    Besides, too many code bits in Windows world get packed into dll format being of absolutely different domains. Regular C code dll is linked to a project a way absolutely different from COM dll or .NET assembly dll. So, to be ultimately real quick you have to ask real domain-specific questions.
    Best regards,
    Igor

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