Windows System Programming Third Edition

Book description

"If you're a systems-level 32-bit or 64-bit Windows developer, whether using the Windows API directly or via .NET interop, you'll definitely want to take a look at this update to Johnson Hart's well-respected and well-loved book. Johnson starts with Windows history and cultural issues and moves through basic and advanced system services in a thoughtful, thorough manner. If Mr. Rogers wrote a book with David Cutler, this is what they'd come up with."
–Chris Sells, Longhorn Content Strategist,
Microsoft Corporation

"While focusing on UNIX developers that are looking to augment their skills or simply jump ship, Windows System Programming, Third Edition is a book that even some seasoned systems-level Windows developers will undoubtedly find useful. This is not your average bland GUI treatise; Hart takes you down to the metal, explains all the relevant concepts clearly and in-depth, and gives you an extensive library of high-quality code examples that can be easily adapted for your own larger applications. Even if you've created server applications before, Windows System Programming will teach you new tricks, shed new light on concepts you thought you'd mastered, and offer new strategies for creating robust and secure solutions."
–Klaus H. Probst, Senior Architect,
Spherion Technology Services; Microsoft MVP

"This book is quite easy to follow; there are clear explanations of everything. Even the explanation of the standards is readable! For a developer not familiar with developing with Windows, Hart's book also provides basic information on where Windows was and where it is today, plus a great explanation of how it is different from Posix and Unix."
–Eric Landes, Microsoft MVP,

"Even advanced developers will always need to have a book like this one on hand when the abstractions of a platform like .NET are inadequate or when they need to know more about how .NET is implemented. And the focus on low-level programming (specifically memory management and IO) and other non-GUI topics makes it stand out as superior among other Windows programming books. In keeping the GUI focus to a minimum, Hart's book is able to be comprehensive on the topics contained within."
–Michael Davidson, IT Analyst

Windows System Programming, Third Edition gives a solid grounding on using the core Windows APIs, includingWin64; is updated for Windows Server 2003, Windows XP, and the Microsoft Visual Studio .NET Framework, and has extensive examples illustrate all topics and show performance impact and tradeoffs

A practical guide to the central features and functions of the Windows API, Windows System Programming, Third Edition, will get you up and running with Windows XP and 2003, as well as other Windows systems. Unlike most Windows programming resources, this book focuses exclusively on the core system services–file system, memory, processes and threads, synchronization, communication, and security–rather than on the more commonly featured graphical user interface functions. Especially geared for those already familiar with UNIX or other high-end operating systems, Windows System Programming, Third Edition, helps you to build on your knowledge base to learn the most important features quickly and easily.

This new edition has been updated and enhanced with coverage of new API functions, network programming, Windows Services, process and thread management, synchronization, and application performance on single and multiprocessor systems. It also describes techniques for porting applications to Win64, the new Windows 64-bit API.

Beginning with an examination of the features required in a single-process application, the text gradually progresses to increasingly sophisticated functions relating to a multithreaded environment. Each chapter contains realistic examples to illustrate the topics. You will find extensive coverage of such critical Windows topics as:

  • File and directory management

  • Character I/O and Unicode

  • The registry

  • Structured exception handling

  • Security services

  • Memory management and DLLs

  • Threads, process management, and scheduling

  • Thread synchronization, including the condition variable model for event and mutex usage

  • Interprocess communication, featuring pipes and mailslots

  • Network programming with sockets

  • Developing Windows Services

  • Timers,Asynchronous I/O, and I/O completion ports

  • Guidelines and trade-offs to improve application performance and reliability

  • Win64, covering architecture, data types, and legacy code migration

  • Short, practical examples illustrate each topic and are included on the companion Web site ( The appendixes provide performance measurements and compare Windows, UNIX, and the C library.

    Table of contents

    1. Contents (1/2)
    2. Contents (2/2)
    3. Figures
    4. Tables
    5. Programs
    6. Preface (1/2)
    7. Preface (2/2)
    8. Chapter 1 Getting Started with Win32 and Win64
      1. Operating System Essentials
      2. Windows Evolution
      3. Windows Versions
      4. The Windows Market Role
      5. Windows, Standards, and Open Systems
      6. Windows Principles
      7. Getting Ready for Win64
      8. The Standard C Library: When to Use It for File Processing
      9. What You Need to Use This Book
      10. Example: A Simple Sequential File Copy
      11. Summary
      12. Exercises
    9. Chapter 2 Using the Windows File System and Character I/O
      1. The Windows File Systems
      2. File Naming
      3. Opening, Reading, Writing, and Closing Files (1/2)
      4. Opening, Reading, Writing, and Closing Files (2/2)
      5. Interlude: Unicode and Generic Characters
      6. Unicode Strategies
      7. Standard Devices and Console I/O
      8. Example: Printing and Prompting
      9. Example: Error Processing
      10. Example: Copying Multiple Files to Standard Output
      11. Example: ASCII to Unicode Conversion
      12. File and Directory Management
      13. Example: Printing the Current Directory
      14. Summary
      15. Exercises
    10. Chapter 3 Advanced File and Directory Processing, and the Registry
      1. The 64-Bit File System
      2. File Pointers
      3. Getting the File Size
      4. Example: Random Record Updates
      5. File Attributes and Directory Processing
      6. Mount Points
      7. Example: Listing File Attributes
      8. Example: Setting File Times
      9. File Processing Strategies
      10. File Locking
      11. The Registry
      12. Registry Management
      13. Example: Listing Registry Keys and Contents
      14. Summary
      15. Exercises
    11. Chapter 4 Exception Handling
      1. Exceptions and Their Handlers
      2. Floating-Point Exceptions
      3. Errors and Exceptions
      4. Example: Treating Errors as Exceptions
      5. Termination Handlers
      6. Example: Using Termination Handlers to Improve Program Quality
      7. Example: Using a Filter Function
      8. Console Control Handlers
      9. Example: A Console Control Handler
      10. Vectored Exception Handling
      11. Summary
      12. Exercises
    12. Chapter 5 Memory Management, Memory-Mapped Files, and DLLs
      1. Win32 and Win64 Memory Management Architecture
      2. Heaps
      3. Managing Heap Memory
      4. Example: Sorting Files with a Binary Search Tree
      5. Memory-Mapped Files (1/2)
      6. Memory-Mapped Files (2/2)
      7. Example: Sequential File Processing with Mapped Files
      8. Example: Sorting a Memory-Mapped File
      9. Example: Using Based Pointers
      10. Dynamic Link Libraries
      11. Example: Explicitly Linking a File Conversion Function
      12. The DLL Entry Point
      13. DLL Version Management
      14. Summary
      15. Exercises
    13. Chapter 6 Process Management
      1. Windows Processes and Threads
      2. Process Creation (1/2)
      3. Process Creation (2/2)
      4. Process Handle Counts
      5. Process Identities
      6. Duplicating Handles
      7. Exiting and Terminating a Process
      8. Waiting for a Process to Terminate
      9. Environment Blocks and Strings
      10. Example: Parallel Pattern Searching
      11. Processes in a Multiprocessor Environment
      12. Process Execution Times
      13. Example: Process Execution Times
      14. Generating Console Control Events
      15. Example: Simple Job Management (1/2)
      16. Example: Simple Job Management (2/2)
      17. Job Objects
      18. Summary
      19. Exercises
    14. Chapter 7 Threads and Scheduling
      1. Thread Overview
      2. Thread Basics
      3. Thread Management
      4. Using the C Library in Threads
      5. Example: Multithreaded Pattern Searching
      6. Performance Impact
      7. The Boss/Worker and Other Threading Models
      8. Example: Merge-Sort—Divide and Conquer to Exploit SMP
      9. Thread Local Storage
      10. Process and Thread Priority and Scheduling
      11. Thread States
      12. Pitfalls and Common Mistakes
      13. Timed Waits
      14. Fibers
      15. Summary
      16. Exercises
    15. Chapter 8 Thread Synchronization
      1. The Need for Thread Synchronization
      2. Thread Synchronization Objects
      3. The CRITICAL_SECTION Object
      4. A CRITICAL_SECTION for Protecting Shared Variables
      5. Example: A Simple Producer/Consumer System
      6. Mutexes
      7. Semaphores
      8. Events
      9. Example: A Producer/Consumer System
      10. More Mutex and CRITICAL_SECTION Guidelines
      11. More Interlocked Functions
      12. Memory Management Performance Considerations
      13. Summary
      14. Exercises
    16. Chapter 9 Synchronization Performance Impact and Guidelines
      1. Synchronization Performance Impact
      2. A Model Program for Performance Experimentation
      3. Tuning SMP Performance with CS Spin Counts
      4. Semaphore “Throttles” to Reduce Thread Contention
      5. Processor Affinity
      6. I/O Completion Ports
      7. Performance Guidelines and Pitfalls
      8. Summary
      9. Exercises
    17. Chapter 10 Advanced Thread Synchronization
      1. The Condition Variable Model and Safety Properties
      2. Using SignalObjectAndWait
      3. Example: A Threshold Barrier Object
      4. A Queue Object
      5. Example: Using Queues in a Multistage Pipeline (1/2)
      6. Example: Using Queues in a Multistage Pipeline (2/2)
      7. Asynchronous Procedure Calls
      8. Queuing Asynchronous Procedure Calls
      9. Alertable Wait States
      10. Safe Thread Cancellation
      11. Pthreads for Application Portability
      12. Thread Stacks and the Number of Threads
      13. Hints for Designing, Debugging, and Testing
      14. Beyond the Windows API
      15. Summary
      16. Exercises
    18. Chapter 11 Interprocess Communication
      1. Anonymous Pipes
      2. Example: I/O Redirection Using an Anonymous Pipe
      3. Named Pipes (1/2)
      4. Named Pipes (2/2)
      5. Named Pipe Transaction Functions
      6. Example: A Client/Server Command Line Processor (1/2)
      7. Example: A Client/Server Command Line Processor (2/2)
      8. Comments on the Client/Server Command Line Processor
      9. Mailslots
      10. Pipe and Mailslot Creation, Connection, and Naming
      11. Example: A Server That Clients Can Locate
      12. Comments on Thread Models
      13. Summary
      14. Exercises
    19. Chapter 12 Network Programming with Windows Sockets
      1. Windows Sockets
      2. Socket Server Functions
      3. Socket Client Functions
      4. Comparing Named Pipes and Sockets
      5. Example: A Socket Message Receive Function
      6. Example: A Socket-Based Client
      7. Example: A Socket-Based Server with New Features
      8. In-Process Servers
      9. Line-Oriented Messages, DLL Entry Points, and TLS
      10. Example: A Thread-Safe DLL for Socket Messages
      11. Example: An Alternative Thread-Safe DLL Strategy
      12. Datagrams
      13. Berkeley Sockets vs. Windows Sockets
      14. Overlapped I/O with Windows Sockets
      15. Windows Sockets 2
      16. Summary
      17. Exercises
    20. Chapter 13 Windows Services
      1. Writing Windows Services—Overview
      2. The main ( ) Function
      3. The ServiceMain ( ) Functions
      4. The Service Control Handler
      5. Example: A Service “Wrapper”
      6. Managing Windows Services
      7. Summary: Service Operation and Management
      8. Example: A Service Control Shell
      9. Sharing Kernel Objects with a Service
      10. Event Logging
      11. Notes on Debugging a Service
      12. Summary
      13. Exercises
    21. Chapter 14 Asynchronous Input/Output and Completion Ports
      1. Overview of Windows Asynchronous I/O
      2. Overlapped I/O
      3. Example: Synchronizing on a File Handle
      4. Example: File Conversion with Overlapped I/O and Multiple Buffers
      5. Extended I/O with Completion Routines
      6. Example: File Conversion with Extended I/O
      7. Asynchronous I/O with Threads
      8. Waitable Timers
      9. Example: Using a Waitable Timer
      10. I/O Completion Ports
      11. Example: A Server Using I/O Completion Ports
      12. Summary
      13. Exercises
    22. Chapter 15 Securing Windows Objects
      1. Security Attributes
      2. Security Overview: The Security Descriptor
      3. Security Descriptor Control Flags
      4. Security Identifiers
      5. Managing ACLs
      6. Example: UNIX-Style Permission for NTFS Files
      7. Example: Initializing Security Attributes
      8. Reading and Changing Security Descriptors
      9. Example: Reading File Permissions
      10. Example: Changing File Permissions
      11. Securing Kernel and Communication Objects
      12. Example: Securing a Process and Its Threads
      13. Overview of Additional Security Features
      14. Summary
      15. Exercises
    23. Chapter 16 Win64 Programming
      1. Current Win64 Status
      2. 64-Bit Architecture Overview
      3. The Win64 Programming Model
      4. The Data Types
      5. Legacy Code Migration
      6. Example: Migrating sortMM (Program 5–5)
      7. Summary
      8. Exercises
    24. Appendix A: Using the Sample Programs
      1. Web Site Organization (1/2)
      2. Web Site Organization (2/2)
      3. Include File Listings (1/2)
      4. Include File Listings (2/2)
      5. Additional Utility Programs
    25. Appendix B: Windows, UNIX, and C Library Comparisons
      1. Chapters 2 and 3: File and Directory Management
      2. Chapter 4: Exception Handling
      3. Chapter 5: Memory Management, Memory-Mapped Files, and DLLs
      4. Chapter 6: Process Management
      5. Chapter 7: Threads and Scheduling
      6. Chapters 8–10: Thread Synchronization
      7. Chapter 11: Interprocess Communication
      8. Chapter 14: Asynchronous I/O
      9. Chapter 15: Securing Windows Objects
    26. Appendix C: Performance Results
      1. Test Configurations
      2. Performance Measurements (1/3)
      3. Performance Measurements (2/3)
      4. Performance Measurements (3/3)
      5. Running the Tests
    27. Bibliography
    28. Index
      1. A
      2. B
      3. C
      4. D
      5. E
      6. F
      7. G
      8. H
      9. I
      10. J
      11. K
      12. L
      13. M
      14. N
      15. O
      16. P
      17. Q
      18. R
      19. S
      20. T
      21. U
      22. V
      23. W

    Product information

    • Title: Windows System Programming Third Edition
    • Author(s): Johnson M. Hart
    • Release date: October 2004
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780321256195