Home > Store

Windows System Programming, 4th Edition

Register your product to gain access to bonus material or receive a coupon.

Windows System Programming, 4th Edition

eBook (Watermarked)

  • Your Price: $47.99
  • List Price: $59.99
  • Includes EPUB, MOBI, and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    MOBI MOBI The eBook format compatible with the Amazon Kindle and Amazon Kindle applications.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

Description

  • Copyright 2010
  • Edition: 4th
  • eBook (Watermarked)
  • ISBN-10: 0-321-77062-5
  • ISBN-13: 978-0-321-77062-2

“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.

Extras

Author's Site

Please visit the companion site at http://www.jmhartsoftware.com.

Sample Content

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

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020