Thus far, we have described two types of libraries: static-link and dynamic-link
libraries. There is a third type of library that is important when working with
dynamic-link libraries: import libraries. An import library contains information that Windows uses to locate code in a dynamic-link library.
During linking, the linker uses static-link libraries and import libraries to resolve references to external functions. When an application uses a function from a static-link library, the linker copies the code for that function into the application's .EXE file. When the application uses a function from a dynamic-link library, however, the linker does not copy any code. Instead, it copies information from the import library—information that indicates where to find the necessary code in the dynamic-link library at run time. While the application is running, this relocation information creates a dynamic link between the executing application and the dynamic-link library.
The following table summarizes the uses of each of the three types of libraries.
Library type |
Linked at link time |
Linked at run time |
Example library |
Example function |
Static | Yes | No | MLIBCEW.LIB | strcpy |
Import | Yes | No | LIBW.LIB | TextOut |
Dynamic | No | Yes | GDI.EXE | TextOut |
As this table indicates, when an application calls the strcpy function in the C run-time library the linker links the application to the library by copying the code of the function from the MLIBCEW.LIB run-time library into the application's .EXE file. But when the application calls the TextOut GDI function, the linker copies location information for TextOut from the LIBW.LIB import library into the .EXE file. It does not copy the code of the function itself. Then, at run time, when the application makes the call to TextOut, Windows uses the location information in the .EXE file to locate TextOut in the dynamic-link library GDI.EXE. It then executes the TextOut function in GDI.EXE. In other words, import libraries provide the connection between application modules and dynamic-link library modules.