In: Computer Science
Briefly describe static linking and dynamic linking. Include the advantages and disadvantages of dynamic linking over static linking.
Describe a Windows DLL.
Suppose you are writing a DLL and need to export the function void CYBR215(). Show the C syntax to export this function for use by other modules or executables.
Q1) Briefly describe static linking and dynamic linking
Static Linking | Dynamic Linking |
In static linking, functions and variables which are defined in external library files are linked inside your executable. That means that the code is actually linked against your code when compiling/linking | With dynamic linking external functions that you use in your software are not linked against your executable. Instead they reside in a external library files which are only referenced by your software. Ie: the compiler/linker instructs the software on where to find the used functions. |
Dynamic linking has the following advantages over static linking:-
Disadvantage of Dynamic Linking over Static Linking:- A potential disadvantage to using Dynamic Linking is that the application is not self-contained; it depends on the existence of a separate Dynamic Linking module. The system terminates processes using load-time dynamic linking if they require a Dynamic Linking that is not found at process startup and gives an error message to the user. The system does not terminate a process using run-time dynamic linking in this situation, but functions exported by the missing Dynamic Linking are not available to the program.
Q2) Describe a Windows DLL - A DLL is a library that contains code and data that can be used by more than one program at the same time. For example, in Windows operating systems, the Comdlg32 DLL performs common dialog box related functions. Therefore, each program can use the functionality that is contained in this DLL to implement an Open dialog box. This helps promote code reuse and efficient memory usage.
By using a DLL, a program can be modularized into separate components. For example, an accounting program may be sold by module. Each module can be loaded into the main program at run time if that module is installed. Because the modules are separate, the load time of the program is faster, and a module is only loaded when that functionality is requested
Mentioned below are some important dll files which user should know for programming ?
COMDLG32.DLL ? Controls the dialog boxes.
GDI32.DLL ? Contains numerous functions for drawing graphics, displaying text, and managing fonts.
KERNEL32.DLL ? Contains hundreds of functions for the management of memory and various processes.
USER32.DLL ? Contains numerous user interface functions. Involved in the creation of program windows and their interactions with each other.
Q3) Suppose you are writing a DLL and need to export the function void CYBR215(). Show the C syntax to export this function for use by other modules or executables
The following code shows a header file that can be used by C and C++ client applications: // MyCFuncs.h #ifdef __cplusplus extern "C" { // only need to export C interface if // used by C++ source code #endif __declspec( dllimport ) void CYBR215(); #ifdef __cplusplus } #endif