How to Talk To Windows. What did it say?

Similar documents
CSE 4/521 Introduction to Operating Systems. Lecture 29 Windows 7 (History, Design Principles, System Components, Programmer Interface) Summer 2018

Windows 7 Overview. Windows 7. Objectives. The History of Windows. CS140M Fall Lake 1

Module 23: Windows NT. Windows NT

Module 23: Windows NT

Module 21: Windows 2000

Module 21: Windows 2000

Operating System Services

The modularity requirement

Appendix C: Windows Operating System Concepts Essentials 8 th Edition

Module 22: Windows XP. Chapter 22: Windows XP. Objectives. Windows XP. History. Design Principles

Chapter 22: Windows XP

Operating System Architecture. CS3026 Operating Systems Lecture 03

Operating System. Operating System Overview. Layers of Computer System. Operating System Objectives. Services Provided by the Operating System

Operating System Overview. Operating System

Chapter 2: Operating-System Structures

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread

Last time: introduction. Networks and Operating Systems ( ) Chapter 2: Processes. This time. General OS structure. The kernel is a program!

Chapter 2: Operating-System Structures. Chapter 2: Operating-System Structures. Objectives. Operating System Services

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

What is a Process. Processes. Programs and Processes. System Classification 3/5/2013. Process: An execution stream and its associated state

CPS221 Lecture: Operating System Functions

Objectives. Chapter 2: Operating-System Structures. 2.1 Operating System Services

Processes. 4: Threads. Problem needs > 1 independent sequential process? Example: Web Server. Last Modified: 9/17/2002 2:27:59 PM

Opening Microsoft Visual Studio. On Microsoft Windows Vista and XP to open the visual studio do the following:

Process Characteristics

CS 390 Chapter 2 Homework Solutions

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Win32 Programming. Jim Fawcett CSE775 Distributed Objects Spring 2012

CPS221 Lecture: Operating System Functions

System Call System Program Linker/Loader with Examples Types of computing Environment

Lecture 2 Operating System Structures (chapter 2)


Operating Systems Overview. Chapter 2

Architectural Support for Operating Systems. Jinkyu Jeong ( Computer Systems Laboratory Sungkyunkwan University

Introduction. CS3026 Operating Systems Lecture 01

Mon Sep 17, 2007 Lecture 3: Process Management

Last class: OS and Architecture. OS and Computer Architecture

Last class: OS and Architecture. Chapter 3: Operating-System Structures. OS and Computer Architecture. Common System Components

Operating Systems: Internals and Design Principles. Chapter 2 Operating System Overview Seventh Edition By William Stallings

Operating-System Structures

Operating System Overview. Chapter 2

Chapter 2. Operating-System Structures

CS30002: Operating Systems. Arobinda Gupta Spring 2017

Chapter 2: Operating-System Structures. Operating System Concepts 8 th Edition

CHAPTER 2: SYSTEM STRUCTURES. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

OPERATING SYSTEMS UNIT - 1

Introduction CHAPTER. Practice Exercises. 1.1 What are the three main purposes of an operating system? Answer: The three main puropses are:

CSE 451 Midterm 1. Name:

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Chapter 2: System Structures

EEE 435 Principles of Operating Systems

PROCESS CONCEPTS. Process Concept Relationship to a Program What is a Process? Process Lifecycle Process Management Inter-Process Communication 2.

Kernels & Processes The Structure of the Operating System

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 22: Remote Procedure Call (RPC)

Chapter 2 Operating-System Structures

For 100% Result Oriented IGNOU Coaching and Project Training Call CPD: ,

Computer-System Architecture (cont.) Symmetrically Constructed Clusters (cont.) Advantages: 1. Greater computational power by running applications

Chapter 3: Operating-System Structures

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

Chapter 2: Operating-System Structures

Operating System. Operating System Overview. Structure of a Computer System. Structure of a Computer System. Structure of a Computer System

Kernel Support for Paravirtualized Guest OS

Here to take you beyond. ECEP Course syllabus. Emertxe Information Technologies ECEP course syllabus

Chapter 2: Operating-System Structures

Module 1 Introduction/OS Overview

Operating System: Chap2 OS Structure. National Tsing-Hua University 2016, Fall Semester

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011

Four Components of a Computer System

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

OPERATING SYSTEM OVERVIEW

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

Chapter 2: Operating-System Structures

Lightweight Remote Procedure Call

Chapter 2: Operating-System Structures. Operating System Concepts Essentials 8 th Edition

8. The C++ language, 1. Programming and Algorithms II Degree in Bioinformatics Fall 2017

CSC 2405: Computer Systems II

Lecture 2 - Fundamental Concepts

Operating Systems, Assignment 2 Threads and Synchronization

Chapter 2: Operating-System

OS structure. Process management. Major OS components. CSE 451: Operating Systems Spring Module 3 Operating System Components and Structure

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edition

W4118 Operating Systems. Junfeng Yang

Operating-System Structures

What s in a traditional process? Concurrency/Parallelism. What s needed? CSE 451: Operating Systems Autumn 2012

Module 1: Introduction

Introduction to PC Operating Systems

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

What s in a process?

Different Ways of Writing Windows Programs

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

CS61 Scribe Notes Date: Topic: Fork, Advanced Virtual Memory. Scribes: Mitchel Cole Emily Lawton Jefferson Lee Wentao Xu

CSc33200: Operating Systems, CS-CCNY, Fall 2003 Jinzhong Niu December 10, Review

Chapter 2: Operating-System Structures

Chapter 2 Operating System Overview

OS and Computer Architecture. Chapter 3: Operating-System Structures. Common System Components. Process Management

Chapter 14 Operating Systems

Chapter 14 Operating Systems

EXPERIMENT NO : M/C Lenovo Think center M700 Ci3,6100,6th Gen. H81, 4GB RAM,500GB HDD

Project #1 Exceptions and Simple System Calls

The Operating System. Chapter 6

Transcription:

How to Talk To Windows What did it say? 1

DOS was essentially subservient. Your program was the master. When you wanted some service from DOS you called DOS it obeyed. You could even bypass DOS and communicate with the PC hardware directly. Why was this OK? DOS the slave Why is this the case? Well DOS is essentially a set of functions in memory that our code can call on. It provides these services as we call on them. Our program is the only program running at any one time. DOS is not a multiprogramming OS. 2

Windows the boss In Windows the OS is the boss. My programs Can t talk directly to hardware All communications (in/out) with the outside world must pass through Windows The user (of my program) really only talks to Windows Windows passes messages to/from my program Why is this necessary? Why? Windows is a multi-programming OS. Lots of programs are running at the same time. Windows must allocate resources. Windows must protect open files. Windows must stop one program interfering with another programs memory etc Windows must interpret all the data (mouse/keyboard/network data packet etc) that arrives into the Pc and decide which program should respond. Which program should be resized. Which program should display the HTL that just arrived in the N/W card. Equally Windows has a look and feel and when you write code for it you must comply. The is a standard for the interface and Windows is the one who enforces this standard. Windows could not achieve any of this if it was subservient. The designers of Win2K chose a client-server architecture for its core implementation. A user application runs as a client of OS services. The user application runs in a special mode of the hardware known generically as user mode. Within this mode, code is restricted to non-harmful operations. For example, through the magic of virtual memory mapping, code cannot touch the memory of other applications (except by mutual agreement with another application). Hardware I/O instructions cannot be executed. Indeed, an entire class of CPU instructions (designated privileged), such as a CPU Halt, cannot be executed. Should the application require the use of any of these prohibited operations, it must make a request of the operating system kernel. A hardware-provided trap mechanism is used to make these requests. Operating system code runs in a mode of the hardware known as kernel mode. Kernel mode code can perform any valid CPU instruction, notably including I/O operations. Memory from any application is exposed to kernel-mode code, providing, of course, that the application memory has not been paged out to disk. 3

Windows 2000 The Windows 2000 kernel is primarily responsible for the scheduling of all thread activity. Other OS components perform the necessary work of memory, process, security, and I/O management. These components are collectively known as the Executive. 4

Executive components Executive components provide the base services for the Windows 2000 operating system (other than thread scheduling), their needs and responsibilities are fairly clear. These components are: SYSTEM SERVICE INTERFACE OBJECT MANAGER CONFIGURATION MANAGER PROCESS MANAGER VIRTUAL MEMORY MANAGER LOCAL PROCEDURE CALL FACILITY I/O MANAGER ACTIVE DIRECTORY SERVICE 5

Windows 2000 The Hardware Abstraction Layer (HAL) isolates the OS and device driver code from the processor and platform dependencies from. In general, when device driver code is ported to a new platform, only a recompile is necessary. How can this work since device driver code is inherently device-, processor-, and platform-specific? Clearly, the device driver code must rely on code (macros) within the HAL to reference hardware registers and buses. 6

Talking to Windows APIs The Executive components of Windows 2000 define and implement core services of the OS however these services are not directly exposed to user-mode applications. Microsoft defines several Application Programming Interfaces (APIs) that user-mode code treats as abstractions of OS services. 7

Talking to Windows APIs These APIs form different environmental subsystems that application code could live within. The Win32 subsystem (our concern here) Others The Virtual DOS Machine (VDM) subsystem provides a 16-bit MSDOS The Windows on Windows (WOW) subsystem supports an environment for oldstyle 16-bit Windows applications for The POSIX subsystem provides API support for Unix-style applications The OS/2 subsystem creates the execution environment for 16-bit OS/2 applications A given application is tightly coupled to exactly one environmental subsystem. Applications cannot make API calls to other environments/subsystems. Only the Win32 subsystem is native Environmental subsystems are generally implemented as separate user-mode processes. The environmental subsystem becomes the server for the usermode client. The server process (i.e., the environmental subsystem) either performs the work to fulfill the request directly or it, in turn, makes a request of the appropriate Executive component. 8

How to Talk to Windows The 32-bit API is huge. It contains thousands of functions broken up into hundreds of categories. It is a comprehensive, all-encompassing programmer interface to the many capabilities provided by the Windows operating system. The API is the same whether you are using Windows 2000 or Windows 98. However, a number of functions will report "not implemented" errors in Windows 98 because they are not supported. The 32-bit API is so called to distinguish it from the older 16-bit API used by standard Windows 3.1 running on top of MS-DOS. The 16-bit API contains all of the Windows and Graphics functions found in the 32-bit API (that is why most older Windows programs port to Windows 2000 and 95 so easily), but the 16-bit API does not have any of the system services found in the 32-bit API. The 32-bit API also includes a number of operations normally found in the standard C libraries, in an attempt to centralize things. For example, the 32-bit API includes functions to move, zero, and copy blocks of memory 9

Who can we talk to? What the MSDN library says : the Win32 API can be grouped into these functional categories: Window Management Window Controls Shell Features Graphics Device Interface System Services International Features Network Services MSDN library ref: The Win32 API allows applications to exploit the power of the 32 bit Windows family of operating systems. The functions, structures, messages, macros, and interfaces form a consistent and uniform API for all of Microsoft's 32-bit platforms. Using the Win32 API, you can develop applications that run successfully on all platforms while still being able to take advantage of unique features and capabilities of any given platform. 10

Using MSDN Library in Visual C++ This library contains a significant amount of reference material Here I m looking at the File and I/O subsection 11

The system services of the 32-bit API The Win32 API you access to Windows system services Processes and threads Interprocess communication Remote Procedure Calls (RPCs) Network communications Serial communications Graphics Device Interface (drawing and painting)* Windows management functions ( creating GUIs)* * Because of MFC you generally do not access either of these sections directly when creating Windows applications in C++. The system services are the core of the operating system. They give you access to the modern capabilities that make the 32-bit versions of Windows interesting: Processes and threads Synchronization Remote Procedure Calls (RPCs) Event logging Network communications TCP/IP networking with UNIX and other machines File mapping Interprocess communication Compressed file access Network drive and printer sharing Serial communications Services (background processing like UNIX daemons) Object and file security Graphics Device Interface (drawing and painting) Windows management functions ( creating GUIs) The other two major sections of the API are the Graphics Device Interface (GDI) for drawing and printing, and the Window Management functions for creating GUIs. Both of these sections are encapsulated by MFC. You will generally write and compile your Win32 programs using either "the Microsoft Win32 SDK" or Visual C++. The SDK is a command-line environment, while Visual C++ is a graphical environment. Visual C++ (but not the SDK) ships with a C++ class library called the Microsoft Foundation Class library, or MFC. MFC makes the creation of GUI programs much easier. It encapsulates all of the window-management and GDI functions available in the 32-bit API. 12

Services Almost all services offered by the OS are modeled with an object* File access (read and write) are offered through an object COM1 access offered through an object *Note: this is not an OO object! 13

My way of talking to objects Owned By OS My APP This handle points to an Object Object Object Actual System Resource Object ObjectActual System Resource Windows uses the concepts of a handle and an object throughout the system services. An object is owned by the operating system and represents a system resource. A handle points to an object. It is possible to create a single object and refer to it with several different handles. You can think of the handles as pointers that let you access the object. A HANDLE is a generic 32-bit pointer. It tells you, as a programmer, nothing about the object it points to, so you are unable to get into the low-level structures and code directly to them. This allows the operating system to change over time without its designers having to worry about code that breaks the rules. 14

Kernel Objects Some of the " kernel objects" defined by the 32-bit API are listed in the notes. Also listed are the function calls that return handles to these objects Here we see a call the function CreateConsoleScreenBuffer and we see it returns a handle to the console object. Object Function Access tokens OpenProcessToken CloseHandle Console CreateConsoleScreenBuffer CloseHandle Console device GetStdHandle CloseHandle Communication port CreateFile CloseHandle Event CreateEvent CloseHandle Event log OpenEventLog CloseEventLog File CreateFile CloseHandle File change FindFirstChangeNotification FindCloseChangeNotification File mapping CreateFile CloseHandle Find file FindFirstFile FindClose Mailslot CreateMailslot CloseHandle Mutex CreateMutex CloseHandle Named pipe CreateNamedPipe CloseHandle Pipe CreatePipe CloseHandle Process CreateProcess CloseHandle Semaphore CreateSemaphoreCloseHandle Thread CreateThread CloseHandle 15

Looking at the function calls Win32 uses an extended set of data types, using C's typedef mechanism These include; 16

Understanding API function calls 1 1 This API function has two parameters. It really wants the addresses (hence LP) of suitable variables in our program, such that the function can fill those variables with data. char computername[max_computername_length + 1]; DWORD computernamelen = MAX_COMPUTERNAME_LENGTH+ 1; success = GetComputerName(computerName, &computernamelen); if (success) cout << "Computer name: " << computername << endl; 3 3 We accept the returned value and work on 2 2 Here we create suitable variables And tell the API function the variables addresses Argument requires a LPTSTR lpbuffer STR =>We need a string data type variable... we ll use a character array LP => and we need to provide the function with the address of our variable. So we create a (big enough) character array, computer name, of size MAX_COMPUTERNAME_LENGTH (defined in <windows.h> plus 1 for terminating character \0 ) When we call GetComputerName() we can supply the name of the array as the first argument because its a synonym for the address of the array Argument requires a LPDWORD nsize DWORD => We use a type DWORD (defined in <windows.h>) variable (basically an integer) that specifies the max number of characters we can put into the character array LP => and we need to provide a the address of the variable that defines the maxlength of the string that can be placed in the character array. 17

Help on line... 18

Sample Program 19

EXERCISE: Your first API calls Write a C++ program that will ask Windows for the following and then prints it to std::cout name of your computer BOOL GetComputerName(); the type of keyboard int GetKeyboardType(); Use the API help to better understand the API function calls. Remember to include <windows.h> to allow you to make the function call char computername[max_computername_length + 1]; DWORD computernamelen = MAX_COMPUTERNAME_LENGTH+ 1; success = GetComputerName(computerName, &computernamelen); if (success) cout << "Computer name: " << computername << endl; 20

Getting computer name and keyboard information 21