Windows System Programming / Edition 4

Hardcover (Print)
Buy New
Buy New from BN.com
$53.08
Buy Used
Buy Used from BN.com
$44.11
(Save 41%)
Item is in good condition but packaging may have signs of shelf wear/aging or torn packaging.
Condition: Used – Good details
Used and New from Other Sellers
Used and New from Other Sellers
from $41.99
Usually ships in 1-2 business days
(Save 44%)
Other sellers (Hardcover)
  • All (14) from $41.99   
  • New (10) from $48.94   
  • Used (4) from $41.99   

Overview

“If you’re writing a native Win32 program or just want to know what the OS is really doing underneath, you need John’s book. He covers the stuff that real systems programmers absolutely must know. Recommended.”

–Chris Sells, Microsoft Corporation

“This fourth edition does a great job of incorporating new features in the Vista, Windows 2008, and Windows 7 API, but also stays true to teaching the foundational elements of building applications that target the Windows OS.”

–Jason Beres, Product Management, Infragistics

The Definitive Guide to Windows API Programming, Fully Updated for Windows 7, Windows Server 2008, and Windows Vista

Windows System Programming, Fourth Edition, now contains extensive new coverage of 64-bit programming, parallelism, multicore systems, and many other crucial topics. Johnson Hart’s robust code examples have been updated and streamlined throughout. They have been debugged and tested in both 32-bit and 64-bit versions, on single and multiprocessor systems, and under Windows 7, Vista, Server 2008, and Windows XP. To clarify program operation, sample programs are now illustrated with dozens of screenshots.

Hart systematically covers Windows externals at the API level, presenting practical coverage of all the services Windows programmers need, and emphasizing how Windows functions actually behave and interact in real-world applications. Hart begins with features used in single-process applications and gradually progresses to more sophisticated functions and multithreaded environments. Topics covered include file systems, memory management, exceptions, processes, threads, synchronization, interprocess communication, Windows services, and security.

New coverage in this edition includes

  • Leveraging parallelism and maximizing performance in multicore systems
  • Promoting source code portability and application interoperability across Windows, Linux, and UNIX
  • Using 64-bit address spaces and ensuring 64-bit/32-bit portability
  • Improving performance and scalability using threads, thread pools, and completion ports
  • Techniques to improve program reliability and performance in all systems
  • Windows performance-enhancing API features available starting with Windows Vista, such as slim reader/writer locks and condition variables

A companion Web site, jmhartsoftware.com, contains all sample code, Visual Studio projects, additional examples, errata, reader comments, and Windows commentary and discussion.

Read More Show Less

Product Details

  • ISBN-13: 9780321657749
  • Publisher: Addison-Wesley
  • Publication date: 3/5/2010
  • Series: Addison-Wesley Microsoft Technology Series
  • Edition description: Fourth Edition
  • Edition number: 4
  • Pages: 609
  • Sales rank: 739,768
  • Product dimensions: 7.50 (w) x 9.30 (h) x 1.50 (d)

Meet the Author

Johnson M. Hart is a consultant specializing in Microsoft Windows and .NET application development, open systems computing, technical training and writing, and software engineering. He has more than twenty-five years of experience as a software engineer, manager, engineering director, and senior technology consultant at Cilk Arts, Inc., Sierra Atlantic, Hewlett-Packard, and Apollo Computer. He served as computer science professor at the University of Kentucky for nine years, and has authored all four editions of Windows System Programming .

Read More Show Less

Table of Contents

Figures xvii

Tables xix

Programs xxi

Program Runs xxv

Preface xxvii

About the Author xxxvii

Chapter 1: Getting Started with Windows 1

Operating System Essentials 1

Windows Evolution 2

Windows Versions 3

The Windows Market Role 5

Windows, Standards, and Open Systems 6

Windows Principles 7

32-bit and 64-bit Source Code Portability 10

The Standard C Library: When to Use It for File Processing 10

What You Need to Use This Book 11

Example: A Simple Sequential File Copy 13

Summary 20

Exercises 22

Chapter 2: Using the Windows File System and Character I/O 25

The Windows File Systems 26

File Naming 27

Opening, Reading, Writing, and Closing Files 28

Interlude: Unicode and Generic Characters 34

Unicode Strategies 37

Example: Error Processing 38

Standard Devices 39

Example: Copying Multiple Files to Standard Output 41

Example: Simple File Encryption 43

File and Directory Management 46

Console I/O 51

Example: Printing and Prompting 53

Example: Printing the Current Directory 55

Summary 56

Exercises 57

Chapter 3: Advanced File and Directory Processing, and the Registry 59

The 64-Bit File System 59

File Pointers 60

Getting the File Size 64

Example: Random Record Updates 65

File Attributes and Directory Processing 70

Example: Listing File Attributes 75

Example: Setting File Times 78

File Processing Strategies 80

File Locking 81

The Registry 86

Registry Management 88

Example: Listing Registry Keys and Contents 92

Summary 96

Exercises 97

Chapter 4: Exception Handling 101

Exceptions and Their Handlers 101

Floating-Point Exceptions 108

Errors and Exceptions 110

Example: Treating Errors as Exceptions 112

Termination Handlers 113

Example: Using Termination Handlers to Improve Program Quality 117

Example: Using a Filter Function 120

Console Control Handlers 124

Example: A Console Control Handler 126

Vectored Exception Handling 128

Summary 129

Exercises 130

Chapter 5: Memory Management, Memory-Mapped Files, and DLLs 131

Windows Memory Management Architecture 132

Heaps 134

Managing Heap Memory 137

Example: Sorting Files with a Binary Search Tree 143

Memory-Mapped Files 149

Example: Sequential File Processing with Mapped Files 156

Example: Sorting a Memory-Mapped File 158

Example: Using Based Pointers 162

Dynamic Link Libraries 167

Example: Explicitly Linking a File Conversion Function 172

The DLL Entry Point 174

DLL Version Management 175

Summary 177

Exercises 178

Chapter 6: Process Management 181

Windows Processes and Threads 181

Process Creation 183

Process Identities 190

Duplicating Handles 191

Exiting and Terminating a Process 192

Waiting for a Process to Terminate 194

Environment Blocks and Strings 195

Example: Parallel Pattern Searching 197

Processes in a Multiprocessor Environment 201

Process Execution Times 202

Example: Process Execution Times 202

Generating Console Control Events 204

Example: Simple Job Management 205

Example: Using Job Objects 215

Summary 219

Exercises 220

Chapter 7: Threads and Scheduling 223

Thread Overview 223

Thread Basics 225

Thread Management 226

Using the C Library in Threads 231

Example: Multithreaded Pattern Searching 232

Performance Impact 235

The Boss/Worker and Other Threading Models 236

Example: Merge-Sort–Exploiting Multiple Processors 237

Introduction to Program Parallelism 244

Thread Local Storage 245

Process and Thread Priority and Scheduling 246

Thread States 249

Pitfalls and Common Mistakes 251

Timed Waits 252

Fibers 253

Summary 256

Exercises 256

Chapter 8: Thread Synchronization 259

The Need for Thread Synchronization 259

Thread Synchronization Objects 268

CRITICAL_SECTION Objects 269

A CRITICAL_SECTION for Protecting Shared Variables 271

Example: A Simple Producer/Consumer System 273

Mutexes 279

Semaphores 284

Events 287

Example: A Producer/Consumer System 289

More Mutex and CRITICAL_SECTION Guidelines 294

More Interlocked Functions 296

Memory Management Performance Considerations 297

Summary 298

Exercises 298

Chapter 9: Locking, Performance, and NT6 Enhancements 301

Synchronization Performance Impact 302

A Model Program for Performance Experimentation 307

Tuning Multiprocessor Performance with CS Spin Counts 307

NT6 Slim Reader/Writer Locks 309

Thread Pools to Reduce Thread Contention 312

I/O Completion Ports 316

NT6 Thread Pools 316

Summary: Locking Performance 324

Parallelism Revisited 325

Processor Affinity 329

Performance Guidelines and Pitfalls 331

Summary 332

Exercises 333

Chapter 10: Advanced Thread Synchronization 335

The Condition Variable Model and Safety Properties 336

Using SignalObjectAndWait 342

Example: A Threshold Barrier Object 344

A Queue Object 348

Example: Using Queues in a Multistage Pipeline 352

Windows NT6 Condition Variables 362

Asynchronous Procedure Calls 366

Queuing Asynchronous Procedure Calls 367

Alertable Wait States 368

Safe Thread Cancellation 371

Pthreads for Application Portability 372

Thread Stacks and the Number of Threads 372

Hints for Designing, Debugging, and Testing 372

Beyond the Windows API 375

Summary 375

Exercises 376

Chapter 11: Interprocess Communication 379

Anonymous Pipes 380

Example: I/O Redirection Using an Anonymous Pipe 380

Named Pipes 384

Named Pipe Transaction Functions 390

Example: A Client/Server Command Line Processor 393

Comments on the Client/Server Command Line Processor 399

Mailslots 401

Pipe and Mailslot Creation, Connection, and Naming 405

Example: A Server That Clients Can Locate 406

Summary 408

Exercises 408

Chapter 12: Network Programming with Windows Sockets 411

Windows Sockets 412

Socket Server Functions 414

Socket Client Functions 419

Comparing Named Pipes and Sockets 421

Example: A Socket Message Receive Function 422

Example: A Socket-Based Client 423

Example: A Socket-Based Server with New Features 426

In-Process Servers 434

Line-Oriented Messages, DLL Entry Points, and TLS 436

Example: A Thread-Safe DLL for Socket Messages 437

Example: An Alternative Thread-Safe DLL Strategy 442

Datagrams 445

Berkeley Sockets versus Windows Sockets 447

Overlapped I/O with Windows Sockets 447

Windows Sockets Additional Features 448

Summary 448

Exercises 449

Chapter 13: Windows Services 453

Writing Windows Services–Overview 454

The main() Function 454

ServiceMain() Functions 455

The Service Control Handler 460

Event Logging 461

Example: A Service “Wrapper” 461

Managing Windows Services 467

Summary: Service Operation and Management 471

Example: A Service Control Shell 472

Sharing Kernel Objects with a Service 476

Notes on Debugging a Service 477

Summary 478

Exercises 478

Chapter 14: Asynchronous Input/Output and Completion Ports 481

Overview of Windows Asynchronous I/O 482

Overlapped I/O 483

Example: Synchronizing on a File Handle 487

Example: File Conversion with Overlapped I/O and Multiple Buffers 487

Extended I/O with Completion Routines 492

Example: File Conversion with Extended I/O 496

Asynchronous I/O with Threads 500

Waitable Timers 501

Example: Using a Waitable Timer 503

I/O Completion Ports 505

Example: A Server Using I/O Completion Ports 509

Summary 516

Exercises 517

Chapter 15: Securing Windows Objects 519

Security Attributes 519

Security Overview: The Security Descriptor 520

Security Descriptor Control Flags 523

Security Identifiers 523

Managing ACLs 525

Example: UNIX-Style Permission for NTFS Files 527

Example: Initializing Security Attributes 531

Reading and Changing Security Descriptors 535

Example: Reading File Permissions 537

Example: Changing File Permissions 538

Securing Kernel and Communication Objects 539

Example: Securing a Process and Its Threads 541

Overview of Additional Security Features 542

Summary 544

Exercises 544

Appendix A: Using the Sample Programs 547

Examples File Organization 548

Appendix B: Source Code Portability: Windows, UNIX, and Linux 549

Source Code Portability Strategies 550

Windows Services for UNIX 550

Source Code Portability for Windows Functionality 551

Chapters 2 and 3: File and Directory Management 556

Chapter 4: Exception Handling 561

Chapter 5: Memory Management, Memory-Mapped Files, and DLLs 562

Chapter 6: Process Management 563

Chapter 7: Threads and Scheduling 565

Chapters 8—10: Thread Synchronization 567

Chapter 11: Interprocess Communication 569

Chapter 14: Asynchronous I/O 571

Chapter 15: Securing Windows Objects 572

Appendix C: Performance Results 575

Test Configurations 575

Performance Measurements 577

Running the Tests 591

Bibliography 593

Index 597

Read More Show Less

Preface

This book describes application development using the Microsoft Windows Application Programming Interface (API), concentrating on the core system services, including the file system, process and thread management, interprocess communication, network programming, and synchronization. User interfaces, internals, and I/O drivers, although important and interesting topics, are beyond the book's scope. The examples concentrate on realistic scenarios, and in many cases the examples can be used as the foundations for real applications.

The Win32/Win64 API, or the Windows API, is supported by Microsoft's family of 32-bit and 64-bit operating systems, which currently consists of Windows XP, Windows 2000, and Windows 2003. Older Windows family members include Windows NT, Me, 98, and 95; these systems are considered obsolete, but they will run many of the example programs. Migration issues from Win32 to the emerging Win64 are discussed as required. Win64, supported as a 64-bit interface on some versions of Windows 2003 and XP, is nearly identical to Win32.

There is no doubt that the Windows API is an important factor for application development, in many cases replacing the POSIX API, supported by UNIX and Linux, as the preferred, or at least peer, API for applications targeted at desktop and server systems. Therefore, many experienced programmers will want to learn the Windows API quickly, and this book is designed to help them do so.

The first objectives are to explain what Windows is, show how to use it in realistic situations, and do so as quickly as possible without burdening the reader with unnecessary detail. This book is, therefore, not a reference guide, but it explains the central features of the most important functions and shows how to use them in practical programming situations. Equipped with this knowledge, the reader will be able to use the comprehensive Microsoft reference documentation to explore details, advanced options, and the more obscure functions as requirements or interests dictate. I have found the Windows API easy to learn using this approach, and I have greatly enjoyed developing Windows programs, despite occasional frustration. This enthusiasm will show through at times, as it should. This does not mean that I feel that Windows is necessarily better than other operating system (OS) APIs, but it certainly has many attractive features.

Many Windows books spend a great deal of time explaining how processes, virtual memory, interprocess communication, and preemptive scheduling work without showing how to use them in realistic situations. A programmer experienced in UNIX, Linux, IBM MVS, OpenVMS, or another OS will be familiar with these concepts and will be impatient to find out how they are implemented in Windows. Most Windows books also spend a great deal of space on user interface programming. This book avoids the user interface, beyond discussing simple character-based console I/O, in the interest of concentrating on the important core features.

The book takes the point of view that Windows is just an OS API, providing a well-understood set of features. Many programmers, regardless of experience level, need to learn Windows quickly, and an understanding of Windows is invaluable in discussing subjects such as Microsoft's Component Object Model (COM). The Windows systems, when compared with other systems, have good, bad, and average features and quality. The purpose of this book is to show how to use those features efficiently and in realistic situations to develop useful, high-quality, and high-performance applications.

Audience

  • Anyone who wants to learn about Windows application development quickly, regardless of previous experience.
  • Programmers and software engineers who must port existing applications, often in UNIX, to Windows for operation on any of the Windows platforms. The book contains many comparisons among Windows, UNIX, and standard C library functions and programming models. All common UNIX functionality, including process management, synchronization, file systems, and interprocess communication, is covered in Windows terms.
  • Readers starting new projects who are not constrained by the need to port existing code. Many aspects of program design and implementation are covered, and Windows functions are used to create useful applications and to solve common programming problems.
  • Programmers using COM and .NET Framework, who will find much of the information here helpful in understanding dynamic link libraries (DLLs), thread usage and models, interfaces, and synchronization.
  • Computer science students at the upper-class undergraduate or beginning graduate level in courses covering systems programming or application development. This book will also be useful to those who are learning multithreaded programming or need to build networked applications. This book would be a useful complementary text to a book such as W. Richard Stevens' Advanced Programming in the UNIX Environment (see the Bibliography) so that students could compare Windows and UNIX. Students in OS courses will find this book to be a useful supplement as it illustrates how a commercially important OS provides essential OS functionality.

The only other assumption, implicit in all the others, is a knowledge of C programming.

Changes in the Third Edition

The third edition presents extensive new material along with significant updating and reorganization of the first and second editions. Objectives of the third edition include the following

  • Cover important new features of Windows XP, 2000, and 2003 along with Win64 migration.
  • Make obsolete Windows 95, 98, and Me (the "Windows 9x" family), since Windows XP is now provided with personal systems and Windows 9x limitations are no longer relevant.* Program examples freely exploit features found only in current Windows versions, even though some programs will not operate on Windows 9x.
  • Provide enhanced coverage of threads and synchronization, including performance, scalability, and reliability considerations. Chapter 9 is new, as are some examples in Chapter 10.
  • Emphasize the increasingly important role and new features of Windows 2000 and 2003 in running high-performance, scalable, multithreaded server applications.
  • Study performance implications of different program designs, especially in multithreaded programs with synchronization and when running on symmetric multiprocessor (SMP) systems.
  • Incorporate reader and student feedback to fix defects, improve explanations, improve the organization, and address numerous details, large and small.

Organization

Chapters are organized topically so that the features required in even a single-threaded application are covered first, followed by process and thread management features, and finally network programming in a multithreaded environment. This organization allows the reader to advance logically from file systems to memory management and file mapping, and then to processes, threads, and synchronization, followed by interprocess and network communication and security. This organization also allows the examples to evolve in a natural way, much as a developer might create a simple prototype and then add additional capability. The advanced features, such as asynchronous I/O and security, appear last.

Within each chapter, after introducing the functionality area, such as process management or memory-mapped files, we discuss important Windows functions and their relationships in detail. Illustrative examples follow. Within the text, only essential parts of programs are listed; complete programs and the required include files, utility functions, and the like are in Appendix A or on the book's Web site (http://www.awprofessional.com/titles/0321256190). Throughout, we identify those features supported only by current Windows versions (XP, 2000, and 2003) but not by earlier versions such as Windows 9x and NT, which do not implement many advanced features. Each chapter suggests related additional reading and gives some exercises. Many exercises address interesting and important issues that did not fit within the normal text, and others allow the reader to explore advanced or specialized topics.

Chapter 1 is a high-level introduction to the Windows OS family and Windows. A simple example program shows the basic elements of Windows programming style and lays the foundation for more advanced Windows features. Win64 and migration issues are introduced in Chapter 1, described extensively in Chapter 16, and included throughout the book as required.

Chapters 2 and 3 deal with file systems, console I/O, file locking, and directory management. Unicode, the extended character set used by Windows, is also introduced in Chapter 2. Examples include sequential and direct file processing, directory traversal, and file archiving. Chapter 3 ends with a discussion of registry management programming, which is similar in many ways to file and directory management.

Chapter 4 introduces Windows' exception handling, including Structured Exception Handling (SEH), which will be used extensively throughout the book. Many books defer SEH to later chapters, but by introducing it early, we will be able to use SEH throughout and thus simplify some programming tasks and improve quality. Vectored exception handling, a newer feature, is also described.

Chapter 5 treats Windows' memory management and shows how to use memory-mapped files both to simplify programming and to improve performance. This chapter also covers DLLs.

Chapter 6 introduces Windows' processes, process management, and simple process synchronization. Chapter 7 then describes thread management in similar terms. Examples in each chapter show the many benefits, including program simplicity and performance, of threads and processes.

Chapters 8, 9, and 10 provide an extended, in-depth treatment of Windows' thread synchronization, one of Windows' strong features. Synchronization is a complex topic, and these chapters use extended examples and well-understood models to help readers obtain the programming and performance benefits of threads while avoiding many of the pitfalls. New material covers performance and scalability issues, which are important when building server-based applications, including those that will run on SMP systems.

Chapters 11 and 12 are concerned with interprocess and interthread communication and networking. Chapter 11 concentrates on the features that are properly part of Windows--namely, anonymous pipes, named pipes, and mailslots. Chapter 12 discusses Windows Sockets, which allow interoperability with non-Windows systems using industry-standard protocols, primarily TCP/IP. Windows Sockets, while not strictly part of the Windows API, provide for network and Internet communication and interoperability, and the subject matter is consistent with the rest of the book. A multithreaded client/server system illustrates how to use interprocess communication along with threads.

Chapter 13 describes how Windows allows server applications, such as the ones created in Chapters 11 and 12, to be converted to Windows Services that can be managed as background servers. Some small programming changes will turn the servers into services.

Chapter 14 shows how to perform asynchronous I/O using overlapped I/O with events and completion routines. You can achieve much the same thing with threads, so examples compare the different solutions for simplicity and performance. The closely related I/O completion ports are, however, necessary for scalable multithreaded servers, so this feature is illustrated with the servers created in earlier chapters. Waitable timers, which require concepts introduced earlier in the chapter,are also described.

Chapter 15 explains Windows' object security, showing, in an example, how to emulate UNIX-style file permissions. Additional examples shows how to secure processes, threads, and named pipes. Security upgrades can then be applied to the earlier examples as appropriate.

Chapter 16 concludes with a description of Win64 programming issues and how to assure that code is portable to Win64. An earlier example is then ported to Win64.

There are three appendixes. Appendix A describes the programs provided on the book's Web site and how to use them. Appendix B contains — tables that compare Windows functions with their counterparts in UNIX and the Standard C library. Appendix C compares the performance of alternative implementations of some of the examples in the text so that you can gauge the trade-offs between Windows features, both basic and advanced, and the C library.

UNIX and C Library Notes and Tables

Within the text at appropriate points, we contrast Windows style and functionality with the comparable UNIX (and Linux) and ANSI Standard C library features. As mentioned, Appendix B presents tables listing these comparable functions. This information is included because many readers are familiar with UNIX and are interested in the comparisons between the two systems. Readers without a UNIX background should feel free to skip those paragraphs in the text, which are indented and set in a smaller font.

Examples

The examples are designed for the following tasks:

  • Illustrate common, representative, and useful applications of the Windows functions.
  • Correspond to real programming situations encountered in program development, consulting, and teaching. Some of my clients and course participants have used the code examples as the bases for their own systems. During my consulting activities, I frequently encounter code that is similar to that used in the examples, and on — occasions I have seen code taken directly from the first or second edition of this book. (Feel free to do so yourself; an acknowledgment in your documentation would be greatly appreciated.) Frequently, this code occurs as part of COM or C++ objects. The examples, subject to time and space constraints, are "real-world" examples and solve "real-world" problems.
  • Emphasize how the functions actually behave and interact, which is not always as you might first expect after reading the documentation. Throughout this book, the text and the examples concentrate on interactions between functions rather than the functions themselves.
  • Grow and expand, adding new capability to a previous solution in an easy and natural manner and exploring alternative implementation techniques.
  • In the earlier chapters, many examples implement UNIX commands, such as ls, touch, chmod, and sort, showing the Windows functions in a familiar context while creating a useful set of utilities.** Different implementations of the same command will also give us an easy way to compare performance benefits available with advanced Windows features. Appendix C contains the results of these performance tests.

Examples in the early chapters are usually short, but the later chapterspresent longer examples when appropriate.

Exercises at the end of each chapter suggest alternative designs, subjects for investigation, and additional functionality that is important but beyond the book's scope. Some exercises are easy, and a few are very challenging. Frequently, clearly labeled defective solutions are provided, because fixing the bugs is an excellent way to sharpen skills.

All examples have been debugged and tested under Windows XP, 2000, and 2003. Where appropriate, they have been tested under Windows 9x and NT. Although the bulk of the development was performed on single-processor, Intelbased systems, most programs were also tested on multiprocessor systems. Theclient/server applications have been tested using multiple clients simultaneously interacting with a server. Nonetheless, there is no guarantee or assurance of program correctness, completeness, or fitness for any purpose. Undoubtedly, even the simplest examples contain defects or will fail under some conditions; such is the fate of nearly all software. I will, however, gratefully appreciate any messages regarding program defects—and, better still, fixes.

The Web Site

The book's Web site (http://www.awprofessional.com/titles/0321256190) contains a downloadable file with complete code and projects for all the book's examples, a number of exercise solutions, alternative implementations of some of the examples, instructions, and performance evaluation tests. This material will be updated periodically to include new material and corrections.

My personal Web site (http://world.std.com/~jmhart/windows.htm) contains book errata, along with additional examples, reader contributions, additional explanations, and much more. PowerPoint slides are also included and can be used for noncommercial instructional purposes. These slides have been used numerous times in professional training courses, and they are also suitable for use in college courses.

The material will be updated as required when defects are fixed and as reader input is received. If you encounter any difficulties with the programs or any material in the book, check these locations first because there may already be a fix or explanation. If that does not answer your question, feel free to send e-mail to jmhart@world.std.com.

Johnson (John) M. Hart
jmhart@world.std.com
August 2004

* Nonetheless, features that do not apply to Windows 9x are noted as appropriate.
** Several commercial and open source products provide complete sets of UNIX utilities; there is no intent to supplement them. These examples, although useful, are primarily intended to illustrate the use of Windows features. A reader who is not familiar with UNIX should not, however, have any difficultyunderstanding the programs or their functionality.

0321256190P10142004

Read More Show Less

Introduction

This book describes application development using the Microsoft Windows Windows Application Programming Interface (API), concentrating on the core system services, including the file system, process and thread management, interprocess communication, network programming, and synchronization. User interfaces, internals, and I/O drivers, although important and interesting topics, are beyond the book's scope. The examples concentrate on realistic scenarios, and in many cases the examples can be used as the foundations for real applications.

The Win32/Win64 API, or the "Windows API", is supported by Microsoft's family of 32-bit and 64-bit operating systems, which currently consists of Windows XP, Windows 2000, and Windows 2003. Older Windows family members include Windows NT, Me, 98, and 95; these systems are considered to be obsolete, but they will run many of the example programs. Migration issues from Win32 to the emerging Win64 are discussed as required. Win64, supported as a 64-bit interface on some versions of Windows 2003 and XP, is nearly identical to Win32.

There is no doubt that the Windows API is an important factor for application development, in many cases replacing the POSIX API, supported by UNIX and Linux, as the preferred, or, at least, peer, API for applications targeted at desktop and server systems. Therefore, many experienced programmers will want to learn the Windows API quickly, and this book is designed to help them do so.

The first objectives are to explain what Windows is, show how to use it in realistic situations, and do so as quickly as possible without burdening the reader with unnecessary detail. This book is, therefore, neithercomprehensive nor a reference guide, but it explains the central features of the most important functions and shows how to use them in practical programming situations. Equipped with this knowledge, the reader will be able to use the comprehensive Microsoft reference documentation to explore details, advanced options, and the more obscure functions as requirements or interests dictate. I have found the Windows API easy to learn using this approach, and I have greatly enjoyed developing Windows programs, despite occasional frustration. This enthusiasm will show through at times, as it should. This does not mean that I feel that Windows is necessarily better than other operating system APIs, but it certainly has many attractive features.

Many Windows books spend a great deal of time explaining how processes, virtual memory, interprocess communication, and preemptive scheduling work without showing how to use them in realistic situations. A programmer experienced in UNIX, Linux, IBM MVS, OpenVMS, or another operating system will be familiar with these concepts and will be impatient to find out how they are implemented in Windows. Most Windows books also spend a great deal of space on user interface programming. This book avoids the user interface, beyond discussing simple character-based console I/O, in the interest of concentrating on the important core features.

The book takes the point of view that Windows is just an operating system (OS) API, providing a well understood set of features. Many programmers, regardless of experience level, need to learn Windows and the Windows operating systems quickly, and an understanding of Windows is invaluable in discussing subjects such as Microsoft's Component Object Model (COM). The Windows systems, when compared with other systems, have good, bad, and average features and quality. The purpose of this book is to show how to use those features efficiently and in realistic situations to develop useful, high-quality, and high-performance applications.

Audience

  • Anyone who wants to learn about Windows application development quickly, regardless of previous experience.
  • Programmers and software engineers who must port existing applications, often in UNIX, to Windows for operation on any of the Windows platforms. The book contains many comparisons among Windows, UNIX, and standard C library functions and programming models. All common UNIX functionality, including process management, synchronization, file systems, and interprocess communication, is covered in Windows terms.
  • Readers starting new projects who are not constrained by the need to port existing code. Many aspects of program design and implementation are covered, and Windows functions are used to create useful applications and to solve common programming problems.
  • Programmers using COM and .NET will find much of the information here helpful in understanding DLLs, thread usage and models, interfaces, and synchronization.
  • Computer science students at the upperclass undergraduate or beginning graduate level in courses covering systems programming or application development. This book will also be useful to those who are learning multithreaded programming or need to build networked applications. This book would be a useful complementary text to a book such as W. Richard Stevens' Advanced Programming in the UNIX Environment (see the Bibliography) so that students could compare Windows and UNIX. Students in operating systems courses will find this book to be a useful supplement as it illustrates how a commercially important operating system provides essential OS functionality.

The only other assumption, implicit in all the others, is a knowledge of C programming.

Changes in the Third Edition

  • The Third Edition includes extensive new material along with significant updating and reorganization of the first and second editions. Objectives of the Third Edition include:
  • Cover important new features of Windows XP, 2000, and 2003 along with Win64 migration.
  • Obsolete Windows 95, 98, and Me (the "Windows 9x" family), since Windows XP is now provided with personal systems and Windows 9x limitations are no longer relevant. Program examples freely exploit features only found in current Windows versions, even though some programs will not operate on Windows 9x.
  • Provide enhanced coverage of threads and synchronization including performance, scalability, and reliability considerations. Chapter 9 is new, as are some examples in Chapter 10.
  • Emphasize the increasingly important role, and new features, of Windows 2000 and 2003 in running high performance, scalable, multithreaded server applications.
  • Study performance implications of different program designs, especially in multithreaded programs with synchronization and when running on SMP systems.
  • Incorporate reader and student feedback to fix defects, improve explanations, improve the organization, and address numerous details, large and small.
  • < are organized topically so that the features required in even a single-threaded application are covered first, followed by process and thread management features, and finally network programming in a multithreaded environment. This organization allows the reader to advance logically from file systems to memory management, and file mapping, and then to processes, threads, and synchronization, followed by interprocess and network communication and security. This organization also allows the examples to evolve in a natural way, much as a developer might create a simple prototype and then add additional capability. The advanced features, such as asynchronous I/O and security, appear last.

    Within each chapter, after introducing the functionality area, such as process management or memory-mapped files, we discuss important Windows functions and their relationships in detail. Illustrative examples follow. Within the text, only essential parts of programs are listed; complete programs and the required include files, utility functions, and the like are in an appendix or on the book's web site (URL TDB). Throughout, we identify those features supported only by current Windows versions (XP, 2000, and 2003) but not by earlier versions such as Windows 9x and NT, which do not implement many advanced features. Each chapter suggests related additional reading and gives some exercises. Many exercises address interesting and important issues that did not fit within the normal text, and others allow the reader to explore advanced or specialized topics.

    Chapter 1 is a high-level introduction to the Windows OS family and Windows. A simple example program shows the basic elements of Windows programming style and lays the foundation for more advanced Windows features. Win64 and migration issues are introduced in Chapter 1, described extensively in Chapter 16, and included throughout the book as required.

    Chapters 2 and 3 deal with file systems, console I/O, file locking, and directory management. Unicode, the extended character set used by Windows, is also introduced in Chapter 2. Examples include sequential and direct file processing, directory traversal, and file archiving. Chapter 3 ends with a discussion of registry management programming, which is similar in many ways to file and directory management.

    Chapter 4 introduces Windows' exception handling, including Structured Exception Handling (SEH), which will be used extensively throughout the book. Many books defer SEH to later chapters, but by introducing it early we will be able to use SEH throughout and thus simplify some programming tasks and improve quality. Vectored exception handling, a newer feature, is also described.

    Chapter 5 treats Windows memory management and shows how to use memory-mapped files both to simplify programming and for performance. This chapter also covers dynamic link libraries (DLLs).

    Chapter 6 introduces Windows processes, process management, and simple process synchronization. Chapter 7 then describes thread management in similar terms. Examples in each chapter show the many benefits, including program simplicity and performance, of threads and processes.

    Chapters 8, 9, and 10 provide an extended, in-depth treatment of Windows thread synchronization, one of Windows' strong features. Synchronization is a complex topic, and these chapters use extended ex understood models to help you obtain the programming and performance benefits of threads while avoiding many of the pitfalls. There is new material covering performance and scalability issues, which are important when building server-based applications, including those that will run on symmetric multiprocessor (SMP) systems.

    Chapters 11 and 12 are concerned with interprocess and interthread communication and networking. Chapter 11 concentrates on the features that are properly part of Windows--namely, anonymous pipes, named pipes, and mailslots. Chapter 12 treats Windows Sockets, which allow interoperability with non-Windows systems using industry-standard protocols, primarily TCP/IP. Windows Sockets, while not strictly part of the Windows API, provide for network and Internet communication and interoperability, and the subject matter is consistent with the rest of the book. A multithreaded client/server system illustrates how to use interprocess communication along with threads.

    Chapter 13 describes how Windows allows server applications, such as the ones created in Chapters 11 and 12, to be converted to "Windows Services" that can be managed as background servers. Some small programming changes will turn the servers into services.

    Chapter 14 shows how to perform asynchronous I/O using overlapped I/O with events and completion routines. You can achieve much the same thing with threads, so examples compare the different solutions for simplicity and performance. The closely related I/O completion ports are, however, necessary for scalable multithreaded servers, so this feature is illustrated with the servers created in earlier chapters. Finally, waitable timers are describe because they require concepts introduced earlier in the chapter.

    Chapter 15 explains Windows object security, showing, in an example, how to emulate UNIX-style file permissions. Additional examples shows how to secure processes, threads, and named pipers. Security upgrades can then be applied to the earlier examples as appropriate.

    Chapter 16 concludes with a description of Win64 programming issues and how to assure that code is portable to Win64. An earlier example is then ported to Win64.

    There are three appendices. Appendix A describes the programs on the website and how to use them. Appendix B contains several tables that compare Windows functions with their counterparts in UNIX and the Standard C library. Appendix C compares the performance of alternative implementations of some of the examples in the text so that you can gauge the trade-offs between Windows features, both basic and advanced, and the C library.

    UNIX and C Library Notes and Tables

    Within the text at appropriate points, we contrast Windows style and functionality with the comparable UNIX (and Linux) and ANSI Standard C library features. Tables listing the comparable functions are presented in Appendix B. This information is included because many readers are familiar with UNIX and are interested in the comparisons between the two systems. Readers without a UNIX background should feel free to skip these paragraphs. Such discussions are indented, in a smaller font.

    Examples

    The examples are designed to do the following:

    • Illustrate common, representative, and useful applications of the Windows functions.
    • Correspond to real programming situa program development, consulting, and teaching. Some of my clients and course participants have used the code examples as the bases for their own systems. During my consulting activities, I frequently encounter code that is similar to that used in the examples, and on several occasions I have seen code taken directly from the First or Second Edition. (Feel free to do so yourself, and an acknowledgment in your documentation would be greatly appreciated.) Frequently, this code occurs as part of COM or C++ objects. The examples, subject to time and space constraints, are "real-world" examples and solve "real-world" problems.
    • Emphasize how the functions actually behave and interact, which is not always as you might first expect after reading the documentation. Throughout this book, the text and the examples concentrate on interactions between functions rather than the functions themselves.
    • Grow and expand, adding new capability to a previous solution in an easy and natural manner and exploring alternative implementation techniques.
    • In the earlier chapters, many examples implement UNIX commands, such as ls, touch, chmod, and sort, showing the Windows functions in a familiar context while creating a useful set of utilities. Different implementations of the same command will also give us an easy way to compare performance benefits available with advanced Windows features. Appendix C contains the results of these performance tests.

    Examples in the early chapters are usually short, but the later chapters present longer examples when appropriate.

    Exercises at the end of each chapter suggest alternative designs, subjects for investigation, an functionality that is important but beyond the book's scope. Some exercises are easy, and a few are very challenging. Frequently, clearly labeled defective solutions are provided, because fixing the bugs is an excellent way to sharpen skills.

    All examples have been debugged and tested under Windows XP, 2000, and 2003. Where appropriate, they have been tested under Windows 9x and NT. Although the bulk of the development was performed on single-processor, Intel-based systems, most programs were also tested on multiprocessor systems. The client/server applications have been tested using multiple clients simultaneously interacting with a server. Nonetheless, there is no guarantee or assurance of program correctness, completeness, or fitness for any purpose. Undoubtedly, even the simplest examples contain defects or will fail under some conditions; such is the fate of nearly all software. I will, however, gratefully appreciate any messages regarding program defects*—nd, better still, fixes.

Read More Show Less

Customer Reviews

Average Rating 4.5
( 3 )
Rating Distribution

5 Star

(1)

4 Star

(2)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 3 Customer Reviews
  • Anonymous

    Posted December 27, 2004

    similar to unix coding

    So much of this book has the flavour of unix systems programming. Part of the reason is the presentation. Hart has deliberately pitched his book towards programmers experienced in unix. But the bulk of the material is inherently not too dissimilar anyway. The code examples are in C, as they usually are in unix. Plus, the book stays away from user interface issues, where there seems to be greater divergence between Microsoft and unix. The discussion of network programming may have the greatest overlap with its unix counterpart, out of all the book's sections. Mostly because both use TCP/IP, so optimal designs tend to converge. Those of you used to Berkeley Sockets are shown an easy port to Win Sockets. Very little rewriting or relearning here. All this in the book is good news for you, if you come from unix programming. It means your skills are very transferable.

    2 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted August 24, 2012

    A good book for low-level Windows stuff

    This book covers lots of low-level, down-to-the-metal, and hard to find Windows topics. It is very useful to programmers who deal with the darkest corner of the OS and for those looking to squeeze the latest features and fastest speed out of their code. Check it out! Recommended for intermediate or advanced developers with C/C++ experience.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 27, 2013

    No text was provided for this review.

Sort by: Showing all of 3 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)