YouTube Icon

Interview Questions.

Top 100+ Dynamic Link Library (dll) Interview Questions And Answers - May 29, 2020

fluid

Top 100+ Dynamic Link Library (dll) Interview Questions And Answers

Question 1. What Is Dll And What Are Their Usages And Advantages?

Answer :

Dynamic Link library or DLL in quick are the extensions of applications. We regularly have not unusual code between many programs and as a result we placed this common section of the code in an extension executable called DLL. The term DLL may be very popular in Windows. However they are additionally present in Linux and Unix and known as Shared Libraries. Shared Libraries regularly include extensions like.So or .Ko. System side DLLs are also gift in conjunction with Operating System kernel inside the shape of tool drivers. They are the extensions of Operating Systems works in the same precept.

In the past while Microsoft Disk Operating System (MS DOS) was used as working machine, executables have been the handiest binary walking in the reminiscence and any common code like C library have been related as static code. The main risks had been:

Additional executable code provides executable storage length in addition to runtime reminiscence requirement,
Executable makes use of C library code that is available at the time of build or compilation. There is no manner to use contemporary C library all through execution. It needs to be rebuild/recompile with modern day C runtime whenever a new C library version released,
In multitasking system wherein multiple task is jogging, there may be no idea of using one example of commonplace executable whilst the use of static linking. It does no longer ensure best one version of C library is going for walks inside the machine. Also it overloads reminiscence requirement of each running undertaking.
Dynamic linking resolves all the shortcomings of static linking. They come with the subsequent blessings:

No extra requirement of reminiscence at runtime or disk garage as a commonplace binary file can be there,
All the application or clients might be using one unmarried model of the common code furnished by means of the DLL,
Operating system hundreds best one instance of the DLL when the first application/customer loads it then for the every subsequent utility it shares the memory pages of the DLL with their system cope with area. Thus there's no pointless reminiscence overload in the machine.
Question 2. What Are The Sections In A Dll Executable/binary?

Answer :

Every DLLs are normal PE executable in home windows or ELF binary in Linux. Thus it has sections like CODE/.TEXT, .DATA,.BSS and many others. 

CODE/.TEXT - phase includes executable hex code.
.DATA - segment incorporates international/static information values.
.BSS - phase is for un-initialized worldwide/static values 
There are also  principal phase of a DLL executable. They are import segment and export section.

Import section(.Idata): Defines the list of symbols/functions it imports from an outside executables/modules.
Export Section(.Edata): Defines the listing of symbols/capabilities that DLL itself exposes to external international to apply.
Any executable in windows follows PE/COFF portable executable and commonplace item layout. These codecs defines how code area, records area and different areas can be arranged. 

There are several equipment available to see the various sections of a PE executable. Some of the widely recognized equipment are PE Viewer, PE Explorer and many others.

Python Interview Questions
Question 3. Where Should We Store Dlls ?

Answer :

Current application path is the default course of any established DLL(s). Thus DLL need to are living in the equal directory because the application executable.

However there may be a few system specific places for storing working machine shared DLLs.

Windows:

%systemroot%
%systemrootp.Cgadget
%systemrootpercentsystem32
%systemrootp.Csystem32drivers
Linux:

/lib
/lib/modules
/usr/neighborhood/lib
The ultimate location in which we will vicinity our DLLs are the directories in the device and or consumer PATH surroundings variable. 

Question four. Who Loads And Links The Dlls?

Answer :

Windows and Linux each has PE/ELF binary loader to load executable and modules. 

A loader in OS hundreds executable/extension when growing a method or whilst an software explicitly calls LoadLibrary() or LoadModule() to load a selected executable. 

A loader loads any executable within the following steps.

Find the executable in cutting-edge/gadget/in course variable
If not observed through blunders
If located check for signature of executable (say test signature of ELF ) for validity
Load the code and records phase in software/machine deal with area.
Links the imported symbols of the application with the exported symbols of the DLL.
Python Tutorial
Question 5. How Many Types Of Linking Are There?

Answer :

There are two most important classes of linking - Static Linking and Dynamic Linking.

Static Linking - In this form of linking, linker links the actual code of the library direct into the code segment of the executable.

Example: Linking C and Graphics library in Turbo C++ for MS DOS.

Linking an application with a archive contains .Obj documents.

Dynamic Linking - Dynamic linking does no longer hyperlink the actual code of the external capabilities. Instead it prepares a list of imported features in .Idata phase and a stub code which actually jumps to the outside feature by using address.

Again Dynamic Linking may be divided into  category

Implicit Dynamic Linking and Explicit Dynamic Linking.

Implicit Dynamic Linking - Links the code with the import library the use of .Idata section mechanism. At the time of application launching all the based DLLs ought to be loaded to begin execution. Also when application ends execution all of the based DLLs have become unloaded.

Explicit Dynamic Linking - This linking does not require any .IMPORT section to listing the feature entries. It is carried out at runtime. User calls the Win32 API LoadLibrary() to load a selected DLL from a specific route on the call for foundation at runtime. Thus there may be no requirement for the DLL to be loaded on the startup time. Also DLL may be unloaded after the use with FreeLibrary() name.

RDBMS Interview Questions
Question 6. What Is Implicit And Explicit Linking In Dynamic Loading?

Answer :

Implicit Dynamic Linking or loading: When application or purchaser makes use of its import table to hyperlink the outside image/functions, it is referred to as implicit linking. In implicit linking software use prototype header and import library to hyperlink an external symbol.

Example: Suppose we have a third birthday celebration math library and upload() is a function/interface we are the use of in our software.

Then the following steps are needed

consist of the maths.H wherein upload() prototype is there as a import feature for compilation,
include math.Lib for linking.
Location math.Dll DLL at the direction of our utility.
Explicit Dynamic Linking/Loading: When application does not link the outside symbol through import library rather it masses the DLL at runtime. It does the identical mechanism as working device does for the duration of loading of the implicit connected DLL calls.

This is achieved via the usage of Win32 APIs like:

LoadLibrary() - hundreds and links a input library shape the DLL route, or modern-day route,
GetProcAddress() - unearths the symbol/function deal with via its call for a loaded DLL
FreeLibrary() - unloads the loaded DLL example
Question 7. How Functions Are Imported And Exported In A Module?

Answer :

Importing capabilities - Importing a characteristic from different module is completed through putting the feature access in function list of .IDATA phase. MS VC++ compiler has precise keyword __declspec(dllimport) to import a feature or variable from an outside module.

Syntax:

Functions: __declspec(dllimport) ;
Variables: __declspec(dllimport) ;

Example:

__declspec(dllimport) int extrn_var;
__declspec(dllimport) int Function1(int a);

Exporting capabilities - Exporting a feature from a module is done via setting the feature access in characteristic list of .EDATA segment. MS VC++ compiler has unique keyword __declspec(dllexport) to export a characteristic or variable from a module.

Syntax:

Functions: __declspec(dllexport) ;
Variables: __declspec(dllexport) ;

Example:

__declspec(dllexport) int extrn_var;
__declspec(dllexport) int Function1(int a);

C Tutorial C Interview Questions
Question 8. How Can I Export A Function From A Module?

Answer :

Exporting a function from a module is finished by using setting the feature entry in characteristic list of .EDATA section. MS VC++ compiler has particular keyword

_declspec(dllexport) to export a function or variable from a module.

Syntax:

Functions: __declspec(dllexport) <function prototype>;
Variables: __declspec(dllexport) <type definition>;

Example:

__declspec(dllexport) int extrn_var;
__declspec(dllexport) int Function1(int a);

The 2d method of exporting a method from a module is executed by using setting function call in a .Def document in EXPORTS phase. We have a later section export a characteristic without __declspec(dllexport) keyword to discuss this in information.

Question nine. What Are Afx Extension Class And Extension Dlls?

Answer :

Regular DLLs lets in us to use MFC in the exported features, however they do not require that the calling software need to additionally use MFC. Thus ordinary DLL can be effortlessly utilized in applications developed in different Windows programming languages like Visual Basic or Delphi. A huge restrict of normal DLL is that it cannot export C++ classes. This restriction has been lifted in an Extension DLL. In an Extension DLL we can export instructions. This forces the patron software to be MFC application. The patron can construct item of the exported magnificence or derive training from it. An extension DLL need to meet two necessities:

An extension DLL dynamically links to the code inside the MFC DLL. Hence an extension DLL calls for that the patron software be dynamically related to the MFC library.
Both the patron program and the extension DLL be synchronized to the same version of the MFC DLLs.
Example:

Class AFX_EXT_CLASS CMyAboutBox: public CDialog

  Public : void ShowDialog(void);
;

Software Engineering Interview Questions
Question 10. How We Use Dynamic Linking In Linux? Give Example?

Answer :

Linux like Windows additionally helps all of the linking of Windows. We shall talk all of the subjects one after the other briefly.

Static Linking:

Let us recollect math.C record. We want to make it as a static library.

First we assemble it with role independent flag on(-fPIC). This is needed for dynamic/static linking.

$cc -fPIC -c math.C

Now make a archive or static lib with the object file.

$ar rc libmath.A math.O

To use this static library in a utility we want to do the following steps:

compile the application code (location math.H in include folder)
$cc -c app.C -Iinclude -o app.O
Link with static library math.A
$ld app.O libmath.A -o app
Run the software
$./app
Implicit Dynamic Linking:

Let us do not forget yet again math.C record for dynamic linking. We want to make it as a dynamic library. First we bring together it with position impartial flag on(-fPIC). This is wanted for dynamic/static linking.

$cc -fPIC -c math.C

Now make a shared library with the item file.

$cc -shared libmath.So math.O

To use this shared library in a application we want to do the subsequent steps:

compile the utility code (region math.H in include folder)
$cc -c app.C -Iinclude -o app.O
Link with import library math.Lib
$ld app.O -lmath -o app
Copy the libmath.So in lib path or contemporary route and run the application
$./app
Explicit Dynamic Linking:

Let us recollect once again math.C report for express linking. The steps for creating a shared library are same as that of implicit linking. 

First we bring together it with role independent flag on(-fPIC). This is wanted for dynamic/static linking.

$cc -fPIC -c math.C

Now make a shared library with the object record.

$cc -shared libmath.So math.O

To use this shared library in a software we want to load the library then locate the feature pointer cope with, invoke the function, and at final dump the library.

Linux provides some dynamic hyperlink library APIs to obtain this. Her are a few useful frequently use APIs:

dlopen() - hundreds a dynamic link binary
dlsym() - returns the characteristic pointer if discovered the feature access
dlclose() - unloads the dynamic hyperlink binary
Sample code:

#include
typedef int (add_func) (int a, int b);
void *lib_handle = NULL;
add_func * add;
int fundamental (int argc, char *argv[])

  lib_handle = (void *)dlopen("libmath.So", RTLD_LAZY); 
  if(lib_handle) 
   
    upload = dlsym(lib_handle, "add");
    if(lib_func)
    
      printf("1 + 2 = %d", upload(1, 2));
    
    else
    
      printf("Function access not found in DLL");
    
    dlclose(lib_handle);
  
  else
  
    printf("Unable to open DLL");
  


Software Engineering Tutorial
Question 11. What Is Resource Dll? When And How We Can Use It?

Answer :

Resource DLL are those which contains recourse associated with binary and no source code. Resource DLL can include the followings

Accelerators
Bitmaps
Icons
Cursors
Menus
Dialogs
HTMLS
String Tables
Toolbars
Versions
Resource DLL can holds resources that may be shared between many programs and therefore minimizes the size of every programs.

Resource DLLs are loaded the usage of LoadLibrary() and the with MFC API AfxSetResourceHandle() we set the loaded resource DLL example as our cutting-edge aid instance. All the decision of loading a resource line LoadIcon() and so on. Will now be loaded from the resource DLL.

Necessary MFC APIs:

HINSTANCE AFXAPI AfxGetResourceHandle() - Returns the contemporary loaded aid take care of.
Void AFXAPI AfxSetResourceHandle(HINSTANCE hInstResource) - Sets the brand new aid take care of for the MFC Application.
SQL Interview Questions
Question 12. How Do I Port My sixteen-bit Dll To A Win32 Dll?

Answer :

If you've got built sixteen-bit DLLs for Windows three.X, you should locate that constructing 32-bit DLLs is extra convenient. Visual C++ offers greater direct aid, that could prevent several steps in DLL creation. 

Python Interview Questions




CFG