Question

In: Computer Science

Briefly describe static linking and dynamic linking. Include the advantages and disadvantages of dynamic linking over static linking.

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.

Solutions

Expert Solution

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:-

  • Multiple processes that load the same DLL at the same base address share a single copy of the DLL in physical memory. Doing this saves system memory and reduces swapping.
  • When the functions in a DLL change, the applications that use them do not need to be recompiled or relinked as long as the function arguments, calling conventions, and return values do not change. In contrast, statically linked object code requires that the application be relinked when the functions change.
  • A DLL can provide after-market support. For example, a display driver DLL can be modified to support a display that was not available when the application was initially shipped.
  • Programs written in different programming languages can call the same DLL function as long as the programs follow the same calling convention that the function uses. The calling convention (such as C, Pascal, or standard call) controls the order in which the calling function must push the arguments onto the stack, whether the function or the calling function is responsible for cleaning up the stack, and whether any arguments are passed in registers

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

Related Solutions

Discuss the advantages and disadvantages of dynamic analysis technique over static analysis techniques.
Discuss the advantages and disadvantages of dynamic analysis technique over static analysis techniques.
What are the differences between static and dynamic IP addresses? What are the advantages of dynamic...
What are the differences between static and dynamic IP addresses? What are the advantages of dynamic IP addresses?
1. Describe the difference between a static web page and a dynamic one. 2.Briefly explain the...
1. Describe the difference between a static web page and a dynamic one. 2.Briefly explain the benefit of using a templating engine when developing a web app. 3.How does the express.js package make it easier to write a web application? 4.Describe how callbacks and promises help with asynchronous programming. 5.What is the difference between a GET and a POST request? When would you use each? 6.Explain what adding the body-parser plugin to your app allows you to do with express.
Briefly describe the dynamic of conformity.
Briefly describe the dynamic of conformity.
Briefly describe the dynamic of groupthink.
Briefly describe the dynamic of groupthink.
Explain in details, what are they with Examples and advantages ? Static CMOS Dynamic Circuits Pass...
Explain in details, what are they with Examples and advantages ? Static CMOS Dynamic Circuits Pass Transistor Curcuirs Domino logic NOTE: please explain jn detail , thank you so much. Keeping in regard to VLSI techniques.
Briefly discuss the advantages and disadvantages of the military draft.
Briefly discuss the advantages and disadvantages of the military draft.
Name and describe the advantages and disadvantages of sexual versus asexual reproduction. Include in your discussion...
Name and describe the advantages and disadvantages of sexual versus asexual reproduction. Include in your discussion the differences between mitosis and meiosis. Lastly, which phase of meiosis is most similar to mitosis and why?
For each of the following entities, briefly describe the advantages and disadvantages: 1) Sole Proprietorship 2)...
For each of the following entities, briefly describe the advantages and disadvantages: 1) Sole Proprietorship 2) Partnership (General partnership - ignore limited partnerships) 3) Classic "C" Corporation 4) "S" Corporation 5) LLC/LLP
Briefly describe some of the advantages and disadvantages of a Zero Based budgeting process. How does...
Briefly describe some of the advantages and disadvantages of a Zero Based budgeting process. How does this compare to the process used in your organization?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT