| |

VerySource

 Forgot password?
 Register
Search
View: 935|Reply: 9

Dynamic library call problem!

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-4 23:30:01
| Show all posts |Read mode
When calling a .dll or .lib file, under what circumstances will both files be required? Under what circumstances is a lib file sufficient? What is the difference between using only .lib and .lib and .dll? ? A little confused
Reply

Use magic Report

0

Threads

45

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 Invalid IP Address

Post time: 2020-3-23 10:45:01
| Show all posts
dll is dynamically loaded

lib is a static library
Reply

Use magic Report

0

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-3-23 11:45:01
| Show all posts
1. Use only lib, only static calls.
2.lib, dll, dynamically call lib as the connection file.

Now generally use the lib, dll method, that is, use the dll method so that the program takes up less space and is easy to upgrade.

In addition, using a lib file to dynamically call a dll is just one method. You can use loadlibrary instead of a lib file.
Reply

Use magic Report

0

Threads

59

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-3-24 20:15:01
| Show all posts
1. The implicit call requires the LIB&DLL, and the explicit loading only requires the DLL and the function prototype.
2.In the case of static connection, only the lib file can be provided.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-26 09:00:01
| Show all posts
The two upstairs summarized it very comprehensively.
Reply

Use magic Report

5

Threads

17

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-3-27 01:45:01
| Show all posts
Linking dynamic libraries into implicit and explicit

Implicit: header files containing exported function / C ++ class declarations are required
       Import library file .lib
       The actual DLL (.dll file)

Shown: Just use LoadLibrary / GetProcAddress / FreeLibrary
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-27 11:45:02
| Show all posts
When only dll is used, use function to load dll; generally use LIB&DLL, just add #pragma comment (lib, "connserverd.lib") to the header file for convenience.
Reply

Use magic Report

0

Threads

59

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-4-14 09:45:01
| Show all posts
Explicit test loading: #pragma comment (lib, "xxx.lib")
Implicit loading, VC 7X environment:
-Project
-Properties
-Linker
-Input
-Additional Dependencies: Type your xxx.lib
Reply

Use magic Report

2

Threads

19

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 Korea, Republic of

Post time: 2020-4-20 23:00:01
| Show all posts
For static connection, as long as .lib, no dll
There is also no .lib and .dll at runtime

There are two ways for dynamic connection
1. When compiling, you need .lib and the corresponding header file that contains the function declaration; you don't need .lib at runtime, but use .dll
2. If the dll is used in the program according to the addressing mode, it is required that the function name should be declared in the .def file when the dll is created. In this way, the .lib and .h files are not needed
Examples of addressing modes
 LONG lResult;
   HINSTANCE hModule;
   // Create a new function pointer data type
   typedef LONG (MULTIPLY2LONGSPROC) (LONG, LONG);
   MULTIPLY2LONGSPROC * pfuncMultiply2Longs = 0;
    // Import the file DYNLINK1.DLL, the file should be in the same directory as the EXE file or in the WINDOWS\SYSTEM\directory
   VERIFY (hModule = :: LoadLibrary ("DYNLINK1.dll"));
   // Get the address of the function Multiply2Longs () in the DLL
   VERIFY (
      pfuncMultiply2Longs =
         (MULTIPLY2LONGSPROC *) :: GetProcAddress (
            (HMODULE) hModule, "Multiply2Longs")
   );
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-14 10:00:02
| Show all posts
Dynamic libraries are easy to upgrade, load on demand, and do not occupy memory (when not in use). Static libraries do not have the burden of loading at runtime, but they are added from the beginning.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list