Win32 Programming Lesson 19: Introduction to DLLs.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

Lecture 2 - Introduction Objective C is used primarily for application development on Apple's Mac OS X and iPhone. On the Apple it is used together with.
Device Drivers Witawas Srisa-an Embedded Systems Design and Implementation.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Module 6: Introduction to C Language ITEI102 Introduction to Programming Structure of C++ Program - Programming Terminologies - Microsoft Visual Studio.
Linking & Loading CS-502 Operating Systems
Operating System Security : David Phillips A Study of Windows Rootkits.
Module 4.2 File management 1. Contents Introduction The file manager Files – the basic unit of storage The need to organise Glossary 2.
Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
Loader- Machine Independent Loader Features
INTRODUCTION OS/2 was initially designed to extend the capabilities of DOS by IBM and Microsoft Corporations. To create a single industry-standard operating.
Introducing the Common Language Runtime for.NET. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution.
Introducing the Common Language Runtime. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution engine.
Chapter 8 Windows Outline Programming Windows 2000 System structure Processes and threads in Windows 2000 Memory management The Windows 2000 file.
OBJECT MODULE FORMATS. The object module format we have employed as an educational device is called OMF (relocatable object format). It’s one of the earliest.
Lecture Set 1 Part B: Understanding Visual Studio and.NET – Structure and Terminology 1/16/ :04 PM.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
SB ScriptBasic Introduction to ScriptBasic There are more people writing programs in BASIC than the number of people capable programming.
‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7.
Lecture Set 2 Part B – Configuring Visual Studio; Configuration Options and The Help System (scan quickly for future reference)
Kernel Modules Giving your Linux more pop since 1995.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Win32 Programming Lesson 20: Advanced DLL Techniques.
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
CS 444 Introduction to Operating Systems
1 2. Program Construction in Java Programming Fundamentals.
Windows 2000 Course Summary Computing Department, Lancaster University, UK.
Introduction to the Windows API n API - Application Programming Interface n an API is the software interface for things such as the OS n an API is the.
Lecture 11 Dynamic link libraries. Differences between static libraries and DLLs In static library code is added to the executable. In DLL, the code is.
Operating Systems Session 1. Contact details TA: Alexander(Sasha) Apartsin ◦ ◦ Office hours: Homepage:
CRT State Stuff Dana Robinson The HDF Group. In the next slide, I show a single executable linked to three dlls. Two dlls and the executable were built.
Windows Memory Architecture 井民全製作. A Process ’ s Virtual Address Space Every Process has its own private virtual address 32-bits processes  4 GB address.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
Operating System What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware. An operating.
CSE451 Linking and Loading Autumn 2002 Gary Kimura Lecture #21 December 9, 2002.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Operating Systems Session 1. Contact details TA: Alexander(Sasha) Apartsin ◦ ◦ Office hours: TA: Sasha Alperovich.
Win32 Programming Lesson 14: Introducing Windows Memory (C Rox…)
Dynamic Link Libraries: Inside Out. Dynamic Link Libraries  About Dynamic-Link Libraries  Dynamic-Link Libraries Hands On  Dynamic Link Library Reference.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
CSE 451: Operating Systems Winter 2011 Linking, Loading and Process Startup Mark Zbikowski Gary Kimura.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
Win32 Programming Lesson 17: Memory Mapped Files (Finally, cool stuff again, all this work is getting tedious!)
Threads. Readings r Silberschatz et al : Chapter 4.
Chapter Eleven Windows XP Professional Application Support.
Program Libraries 1. What is a program library? A library is a collection of implementations of behavior, written in terms of a language, that has a well-defined.
Lecture Set 1 Part B: Understanding Visual Studio and.NET – Structure and Terminology 1/16/ :04 PM.
Kernel Structure and Infrastructure David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Multiple file project management & Makefile
Topic 2: Hardware and Software
Day 12 Threads.
Linking & Loading.
Chapter 4 Threads.
CS-3013 Operating Systems C-term 2008
Threads and Locks.
Chapter 4: Threads.
Machine Independent Features
Chapter 2: System Structures
Java Programming Arrays
Memory Management Tasks
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads Chapter 4.
The Assembly Language Level
Linking & Loading CS-502 Operating Systems
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Linking & Loading CS-502 Operating Systems
Introduction to AppDomains
CS Introduction to Operating Systems
Presentation transcript:

Win32 Programming Lesson 19: Introduction to DLLs

Where are we?  Memory allocation: sorted  Processes and Threads: Done  But… how does Windows structure its executables – what are DLLs and how can we use them to our advantage?

DLLs  Understanding DLLs is essential to understanding Windows  Three most important: Kernel32: Memory, processes and threads User32: User interface tasks GDI32: Graphics  However, Windows contains lots of DLLs  The entire Win32 API is in DLLs

DLL Features  Using DLLs: Extends the features of an application Language-independent (that is, you can write DLLs in many different languages) Simplify project management (modular development and versioning) Conserve memory (remember, DLLs share memory) Resource sharing (shared dialogue boxes, for example) Helpful for localization (different DLLs for different locales) Platform independence (loading on older versions, for example) Special Functions (like hooking into existing applications :: evil grin :: )

DLLs and the Process  To use a DLL a Process needs to load it into its address space  Once this occurs, the DLL looks, for all intents and purposes, like the part of the process, but the DLL is shared between multiple processes How? Remember PAGE_WRITECOPY?

Implications  Because of the close relationship of the DLL to the process objects created by the DLL are owned by the process If the DLL calls VirtualAlloc, for example, that memory counts against the process’ usage If the DLL is later unmapped this memory is not automatically freed

Code Problem  The temptation is to always free memory allocated by the DLL directly – that is, if the DLL uses malloc to provide some memory, the process should call free when it’s done  But this is WRONG!  What if the underlying libraries are different?  If a DLL allocated memory, it should provide a call to free it. Ignore this at your own peril.

How DLLs work  For the sake of this discussion, we’ll talk about “executables” (programs) and DLLs (modules) even though DLLs are executable themselves  We’ll look at the lifecycle of a DLL and executable

First  Before we can use a DLL you need to build it  This means we tell Visual Studio that we’re building a DLL  Create a header file that details the exported types  Linker produces a.lib file if at least one function is exported  Linker produces a.dll file

Second  Build an application using the DLL  Compiler uses DLL header file to build.obj files  The.lib file is used to resolve imported functions

Headers  One of the most important parts of the DLL is the header file, as this will be used when compiling programs which use the DLL  Best to use the same header file for building the DLL as for building files which use the DLL  You can look at exports and imports using dumpbin (from VS 2013)

Running the Executable  The OS looks for the needed imports  Where? The directory containing the executable image file The process’s current directory The Windows system directory The Windows directory The directories listed in the PATH environment variable

Assignment  Write your own DLL  Create a.h file which can be used by programs which call your DLL  Recast your linked list program (remember that first assignment!) as a linked-list DLL which exports the functions I specified  Make sure you work out how to free memory correctly in your DLL  Write a program which compiles and runs using your linked list DLL