



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of importing libraries and dlls in windows, including their calling conventions, variable scope, and the use of threads. Topics covered include the importance of import libraries, the role of system dlls, the stdcall convention, variable sharing, and the creation and advantages of threads.
Typology: Study notes
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Import Library is statically linked to Executable module.
Example of Import libraries in windows are:
Important System DLLs are
Functions used in DLL’s are normally use __stdcall calling convention. __stdcall calling convention is a standard calling convention used by the APIs in Windows. This calling convention cleans the stack after returning the called procedure automatically. No extra code is needed to clean out stack. __stdcall calling convention pushes the arguments in stack from right to left order.
Variables defined in DLL have scope in memory until the DLL is loaded. After unloading, the variable scope is vanished. Locally defined variables are accessed within the DLL only. The variables that are set to export variables can be accessed outside the DLL if the DLL is statically linked.
Variables can be shared across multiple processes by making the separate data section as following.
#pragma data_seg( [ [ { push | pop } , ] [ identifier , ] ] [ "segment- name " [, " segment-class " ] )
Specifies the data segment where initialized variables are stored in the .obj file. OBJ files can be viewed with the dumpbin application. The default segment in the .obj file for initialized variables is .data. Variables initialized to zero are considered uninitialized and are stored in .bss.
data_seg with no parameters resets the segment to .data.
push (optional) Puts a record on the internal compiler stack. A push can have an identifier and segment-name. pop (optional) Removes a record from the top of the internal compiler stack. identifier (optional) When used with push , assigns a name to the record on the internal compiler stack. When used with pop , pops records off the internal stack until identifier is removed; if identifier is not found on the internal stack, nothing is popped.
identifier enables multiple records to be popped with a single pop command.
"segment-name" (optional) The name of a segment_._ When used with pop , the stack is popped and segment- name becomes the active segment name.
Example // pragma_directive_data_seg.cpp int h = 1; // stored in .data int i = 0; // stored in .bss #pragma data_seg(".my_data1") int j = 1; // stored in "my_data1"
#pragma data_seg(push, stack1, ".my_data2") int l = 2; // stored in "my_data2"
#pragma data_seg(pop, stack1) // pop stack1 off the stack int m = 3; // stored in "stack_data1"
int main() { }
Data allocated using data_seg does not retain any information about its location.
#pragma comment(linker, “/SECTION: seg_data1, RWS”)
/SECTION: name , [E][R][W][S][D][K][L][P][X][,ALIGN= # ]
The /SECTION option changes the attributes of a section, overriding the attributes set when the .obj file for the section was compiled.
A section in a portable executable (PE) file is roughly equivalent to a segment or the resources in a new executable (NE) file. Sections contain either code or data. Unlike segments, sections are blocks of contiguous memory with no size constraints. Some sections contain code or data that your program declared and uses directly, while other data sections are created for you by the linker and library manager (lib.exe) and contain information vital to the operating system.
To set this linker option in the Visual Studio development environment
Resource Only DLL contains only resource of different language and local types. Resource only DLLs do not contain Entry Point or any DllMain Function.
Use of resource-only DLL is for internationalization.
Version information makes it easier for applications to install files properly and enables setup programs to analyze files currently installed. The version-information resource contains the file's version number, intended operating system, and original file name.
You can use the version information functions to determine where a file should be installed and identify conflicts with currently installed files. These functions enable you to avoid the following problems:
The version information functions enable applications to query a version resource for file information and present the information in a clear format. This information includes the file's purpose, author, version number, and so on.
You can add version information to any files that can have Microsoft® Windows® resources, such as dynamic-link libraries (DLLs), executable files, or font files. To add the information, create a VERSIONINFO Resource and use the resource compiler to compile the resource.
The GetFileVersionInfo function retrieves version information for the specified file.
BOOL GetFileVersionInfo(
LPTSTR lptstrFilename , //file name whose version is to get*/
DWORD dwHandle , /unused/ DWORD dwLen , /length of the given buffer/ LPVOID lpData /* buffer*/ );
lptstrFilename: Pointer to a null-terminated string that specifies the name of the file of interest. If a full path is not specified, the function uses the search sequence specified by the LoadLibrary function.
dwHandle: This parameter is ignored.
dwLen: Specifies the size, in bytes, of the buffer pointed to by the lpData parameter.
Call the GetFileVersionInfoSize function first to determine the size, in bytes, of a file's version information. The dwLen member should be equal to or greater than that value.
If the buffer pointed to by lpData is not large enough, the function truncates the file's version information to the size of the buffer.
lpData: Pointer to a buffer that receives the file-version information.
You can use this value in a subsequent call to the VerQueryValue function to retrieve data from the buffer.
Return Value: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.
Call the GetFileVersionInfoSize function before calling the GetFileVersionInfo function. To retrieve information from the file-version information buffer, use the VerQueryValue function.
Message Queue is created when every any GDI function call is made or sendmessage or post message function calls are made. Message Queue can be attached to every thread either it is User interface thread or worker threads.
User Interface threads always a message queue.
elapses, allowing another thread to run. When the system switches from one thread to another, it saves the context of the preempted thread and restores the saved context of the next thread in the queue.
The length of the time slice depends on the operating system and the processor. Because each time slice is small (approximately 20 milliseconds), multiple threads appear to be executing at the same time. This is actually the case on multiprocessor systems, where the executable threads are distributed among the available processors.
Note: You must use caution when using multiple threads in an application, because system performance can decrease if there are too many threads.
Multitasking Operating systems are useful to run applications simultaneously. Threads and processes are the key features of Operating systems. In this lecture we studied about variable sharing in DLLs, variable scope in DLLs, DLL Versioning, Resource only DLLs, Threads and their advantages and disadvantages. Many Threads can work better than using single thread sometime.