Are you looking to kick-start your career with Dynamic Link Library job? Wisdom jobs is the number one leading job portal that provides the necessary information on the jobs you are searching for. Dynamic Link Library is the concept of implementing the shared library in operating systems. Generally, these files have .dll extension. DLL jobs include various positions such as System analyst, the Excel developer and senior engineer etc. Wisdom jobs provide you with Dynamic Link Library job interview questions and answers page designed by our experts that can help you to gain further knowledge on the subject and to excel your interview clearing ability. Register at our jobs portal to get all the latest and detailed information on the jobs you applied for www.wisdomjobs.com.
Question 1. What Is Dll And What Are Their Usages And Advantages?
Answer :
Dynamic Link library or DLL in short are the extensions of applications. We often have common code between many applications and thus we put this common section of the code in an extension executable called DLL. The term DLL is very popular in Windows. However they are also present in Linux and Unix and known as Shared Libraries. Shared Libraries often come with extensions like.so or .ko. System side DLLs are also present along with Operating System kernel in the form of device drivers. They are the extensions of Operating Systems works in the same principle.
In the past when Microsoft Disk Operating System (MS DOS) was used as operating system, executables were the only binary running in the memory and any common code like C library were linked as static code. The main disadvantages were:
Dynamic linking resolves all the shortcomings of static linking. They come with the following advantages:
Question 2. What Are The Sections In A Dll Executable/binary?
Answer :
Every DLLs are regular PE executable in windows or ELF binary in Linux. Thus it has sections like CODE/.TEXT, .DATA,.BSS etc.
There are also two major section of a DLL executable. They are import section and export section.
Any executable in windows follows PE/COFF portable executable and common object format. These formats defines how code area, data area and other areas will be arranged.
There are several tools available to see the various sections of a PE executable. Some of the well known tools are PE Viewer, PE Explorer etc.
Question 3. Where Should We Store Dlls ?
Answer :
Current application path is the default path of any dependent DLL(s). Thus DLL should reside in the same directory as the application executable.
However there is some system specific locations for storing operating system shared DLLs.
Windows:
Linux:
The last location where we can place our DLLs are the directories in the system and or user PATH environment variable.
Question 4. Who Loads And Links The Dlls?
Answer :
Windows and Linux both has PE/ELF binary loader to load executable and modules.
A loader in OS loads executable/extension when creating a process or when an application explicitly calls LoadLibrary() or LoadModule() to load a particular executable.
A loader loads any executable in the following steps.
Question 5. How Many Types Of Linking Are There?
Answer :
There are two main categories of linking - Static Linking and Dynamic Linking.
Static Linking - In this type of linking, linker links the actual code of the library direct into the code section of the executable.
Example: Linking C and Graphics library in Turbo C++ for MS DOS.
Linking an application with a archive contains .obj files.
Dynamic Linking - Dynamic linking does not link the actual code of the external functions. Instead it prepares a list of imported functions in .idata section and a stub code which actually jumps to the external function by address.
Again Dynamic Linking can be divided into two category
Implicit Dynamic Linking and Explicit Dynamic Linking.
Implicit Dynamic Linking - Links the code with the import library using .idata section mechanism. At the time of application launching all the dependent DLLs should be loaded to start execution. Also when application ends execution all the dependent DLLs are getting unloaded.
Explicit Dynamic Linking - This linking does not require any .IMPORT section to list the function entries. It is done at runtime. User calls the Win32 API LoadLibrary() to load a particular DLL from a specific path on the demand basis at runtime. Thus there is no requirement for the DLL to be loaded at the startup time. Also DLL can be unloaded after the use with FreeLibrary() call.
Question 6. What Is Implicit And Explicit Linking In Dynamic Loading?
Answer :
Implicit Dynamic Linking or loading: When application or client uses its import table to link the external symbol/functions, it is called implicit linking. In implicit linking application use prototype header and import library to link an external symbol.
Example: Suppose we have a third party math library and add() is a function/interface we are using in our application.
Then the following steps are needed
Explicit Dynamic Linking/Loading: When application does not link the external symbol by import library rather it loads the DLL at runtime. It does the same mechanism as operating system does during loading of the implicit linked DLL calls.
This is done by using Win32 APIs like:
Question 7. How Functions Are Imported And Exported In A Module?
Answer :
Importing functions - Importing a function from other module is done by placing the function entry in function list of .IDATA section. MS VC++ compiler has specific keyword __declspec(dllimport) to import a function or variable from an external module.
Syntax:
Functions: __declspec(dllimport) ;
Variables: __declspec(dllimport) ;
Example:
__declspec(dllimport) int extrn_var;
__declspec(dllimport) int Function1(int a);
Exporting functions - Exporting a function from a module is done by placing the function entry in function list of .EDATA section. MS VC++ compiler has specific keyword __declspec(dllexport) to export a function or variable from a module.
Syntax:
Functions: __declspec(dllexport) ;
Variables: __declspec(dllexport) ;
Example:
__declspec(dllexport) int extrn_var;
__declspec(dllexport) int Function1(int a);
Question 8. How Can I Export A Function From A Module?
Answer :
Exporting a function from a module is done by placing the function entry in function list of .EDATA section. MS VC++ compiler has specific 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 second method of exporting a method from a module is done by placing function name in a .def file in EXPORTS section. We have a later section export a function without __declspec(dllexport) keyword to discuss this in details.
Question 9. What Are Afx Extension Class And Extension Dlls?
Answer :
Regular DLLs allows us to use MFC in the exported functions, but they do not require that the calling application should also use MFC. Thus regular DLL can be easily used in programs developed in other Windows programming languages like Visual Basic or Delphi. A big restriction of regular DLL is that it cannot export C++ classes. This restriction has been lifted in an Extension DLL. In an Extension DLL we can export classes. This forces the client application to be MFC application. The client can construct object of the exported class or derive classes from it. An extension DLL should meet two requirements:
Example:
Class AFX_EXT_CLASS CMyAboutBox: public CDialog
{
Public : void ShowDialog(void);
};
Question 10. How We Use Dynamic Linking In Linux? Give Example?
Answer :
Linux like Windows also supports all the linking of Windows. We shall discuss all the topics one by one briefly.
Static Linking:
Let us consider math.c file. We want to make it as a static library.
First we compile it with position 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 application we need to do the following steps:
Implicit Dynamic Linking:
Let us consider once again math.c file for dynamic linking. We want to make it as a dynamic library. First we compile it with position independent flag on(-fPIC). This is needed for dynamic/static linking.
$cc -fPIC -c math.c
Now make a shared library with the object file.
$cc -shared libmath.so math.o
To use this shared library in a application we need to do the following steps:
Explicit Dynamic Linking:
Let us consider once again math.c file for explicit linking. The steps for creating a shared library are same as that of implicit linking.
First we compile it with position independent flag on(-fPIC). This is needed for dynamic/static linking.
$cc -fPIC -c math.c
Now make a shared library with the object file.
$cc -shared libmath.so math.o
To use this shared library in a application we need to load the library then find the function pointer address, invoke the function, and at last unload the library.
Linux provides some dynamic link library APIs to achieve this. Her are some useful frequently use APIs:
Sample code:
#include
typedef int (add_func) (int a, int b);
void *lib_handle = NULL;
add_func * add;
int main (int argc, char *argv[])
{
lib_handle = (void *)dlopen("libmath.so", RTLD_LAZY);
if(lib_handle)
{
add = dlsym(lib_handle, "add");
if(lib_func)
{
printf("1 + 2 = %d", add(1, 2));
}
else
{
printf("Function entry not found in DLL");
}
dlclose(lib_handle);
}
else
{
printf("Unable to open DLL");
}
}
Question 11. What Is Resource Dll? When And How We Can Use It?
Answer :
Resource DLL are those which contains recourse related to binary and no source code. Resource DLL can contain the followings
Resource DLL can holds resources that can be shared between many applications and thus minimizes the size of each applications.
Resource DLLs are loaded using LoadLibrary() and the with MFC API AfxSetResourceHandle() we set the loaded resource DLL instance as our current resource instance. All the call of loading a resource line LoadIcon() etc. will now be loaded from the resource DLL.
Necessary MFC APIs:
Question 12. How Do I Port My 16-bit Dll To A Win32 Dll?
Answer :
If you have built 16-bit DLLs for Windows 3.x, you should find that building 32-bit DLLs is more convenient. Visual C++ offers more direct support, which can save you several steps in DLL creation.
Dynamic Link Library (DLL) Related Tutorials |
|
---|---|
Python Tutorial | C Tutorial |
Software Engineering Tutorial | Framework7 Tutorial |
Dynamic Link Library (DLL) Related Practice Tests |
|
---|---|
Python Practice Tests | RDBMS Practice Tests |
C Practice Tests | Software Engineering Practice Tests |
SQL Practice Tests | Java-Multithreading Practice Tests |
OOPS Practice Tests |
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.