Register your product to gain access to bonus material or receive a coupon.
With Win32 System Programming, you can capitalize on your knowledge of high-end operating systems such as UNIX, MVS, and VMS to learn Windows system programming quickly. Written from the perspective of an experienced programmer, the book presents the core operating system services of Win32, the common API for the Windows 95 and Windows NT operating systems. It explains Win32 functions clearly, with numerous comparisons to corresponding UNIX calls, and highlights features unique to Win32.
Because most experienced programmers are already familiar with processes, virtual memory, and preemptive scheduling, the book spends little time introducing these concepts, but instead shows how they are implemented in Win32. This text is for programmers using systems services, and focuses on the management of core operating systems resources rather than the graphical user interface.
Win32 System Programming offers extensive coverage of file systems, memory management, Structured Exception Handling, and security. In particular, it delves deeply into processes and threads, with detailed explanations of process synchronization, interprocess communication, and memory mapping. You will also find discussions of other advanced topics including file locking, DLLs, asynchronous I/O, fibers, and the registry.
Numerous realistic examples demonstrate many of Win32's most sophisticated features. In addition, the book compares the performance of alternative implementations of some of these examples to illustrate the trade-offs between various Win32 features and the C library. The accompanying CD-ROM contains all of the code examples in the text, a suite of programs for testing system performance, and a collection of UNIX-like utilities.
1. Windows NT and Windows 95.
Windows 95 and Windows NT: Overview.
Operating System Essentials.
Win32, Windows NT, and Windows 95.
Win32, Standards, and Open Systems.
What You Need to Use This Book.
Win32 Principles.
The Standard C Library: When to Use It.
Example: A Simple Sequential File Copy.
Summary.
Exercises.
The Win32 File Systems.
Win32 File Naming.
Opening, Reading, Writing, and Closing Files.
Interlude: Unicode and Generic Characters.
Unicode Strategies.
Standard Devices and Console I/O.
Example: Printing and Prompting.
Example: Error Processing.
Example: Copying Multiple Files to Standard Output.
Example: ASCII to Unicode Conversion.
File and Directory Management.
Example: Printing the Current Directory.
Summary.
Exercises.
The 64-Bit File System.
File Pointers.
Getting the File Size.
Example: Viewing the Tail of a File.
File Attributes and Directory Searching.
Example: A File Delete Utility.
Example: Listing File Attributes.
Example: Setting File Times.
File Processing Strategies.
Summary.
Exercises.
Exceptions and Their Handlers.
Floating-Point Exceptions.
Errors and Exceptions.
Example: Treating Errors as Exceptions.
Termination Handlers.
Example: Processing Exceptions and Completion.
Console Control Handlers.
Example: A Console Control Handler.
Summary.
Exercises.
Win32 Memory Management Architecture.
Heaps.
Managing Heap Memory.
Example: Sorting Files with a Binary Search Tree.
Memory-Mapped Files.
Example: Sequential File Processing with Mapped Files.
Example: Sorting a Memory-Mapped File.
Example: Using Based Pointers.
Summary.
Exercises.
Security Attributes.
Security Overview: The Security Descriptor.
Security Identifiers.
Managing ACLs.
Example: UNIX-Style Permission for NTFS Files.
Example: Initializing Security Attributes.
Reading and Changing Security Descriptors.
Example: Reading File Permissions.
Example: Changing File Permissions.
Overview of Additional Security Features.
Summary.
Exercises.
Win32 Processes and Threads.
Process Creation.
Process Identities.
Duplicating Handles.
Exiting and Terminating a Process.
Waiting for a Process to Terminate.
Environment Blocks and Strings.
Example: Parallel Pattern Searching.
Process Execution Times.
Example: Process Execution Times.
File Locking.
Generating Console Control Events.
Example: Simple Job Management.
Timers.
Example: A Periodic Alarm.
Timed Waits.
Summary.
Exercises.
Anonymous Pipes.
Example: I/O Redirection Using an Anonymous Pipe.
Named Pipes.
Named Pipe Convenience Functions.
Example: A Simple Client/Server Command Line Processor.
Comments on the Client/Server Command Line Processor.
Mailslots.
Pipe and Mailslot Creation, Connection, and Naming.
Example: A Server That Clients Can Locate.
Summary.
Exercises.
Overview of Threads.
Thread Basics.
Thread Management.
Using the C Library in Threads.
Example: Multithreaded Pattern Searching.
Example: Merge-Sort/Divide and Conquer to Exploit SMP.
Thread Local Storage.
Process and Thread Priority and Scheduling.
Thread States.
Summary.
Exercises.
Thread-Safe Code.
Thread and Process Synchronization Objects.
Critical Sections.
Example: Protecting Shared Variables with Critical Sections.
Mutexes.
Semaphores.
Examples: Using Semaphores.
Events.
Example: A Connection-Oriented Client.
Example: The Threaded Server/Pipe and Thread Management.
Thread Security and Impersonation.
Comments on Thread Models.
Summary.
Exercises.
Dynamic Link Libraries.
Example: Explicitly Linking a File Conversion Function.
Example: An In-Process Command Server.
Example: A DLL Server.
The IIS and ISAPI.
Example: A Skeleton ISAPI DLL.
Summary.
Exercises.
Overview of Win32 Asynchronous I/O.
Overlapped I/O.
Example: Synchronizing on a File Handle.
Example: File Conversion with Overlapped I/O and Multiple Buffers.
Extended I/O with Completion Routines.
Example: File Conversion with Extended I/O.
Asynchronous I/O with Threads.
Overview of I/O Completion Ports.
Summary.
Exercises.
Fibers.
The Registry.
Beyond the System Services.
Summary.
Exercises.
Disc Organization.
Include File Listings.
Additional Utility Programs.
Chapters 3 and 4: File and Directory Management.
Chapter 5: Structured Exception Handling and Timers.
Chapter 6: Memory Management and Memory-Mapped Files.
Chapter 7: Security.
Chapter 8: Process Management.
Chapter 9: Interprocess Communication.
Chapter 10: Thread Management.
Chapter 11: Win32 Synchronization.
Chapter 13: Asynchronous I/O.
Test Configurations.
Performance Measurements.
Running the Tests.
This book shows how to use the Win32 Application Programming Interface (API), concentrating on the core system services, including the file system, process and thread management, interprocess communication, and synchronization. User interfaces, network programming, internals, and I/O drivers, although important and interesting topics, are outside the book's scope. The examples concentrate on scenarios that are likely to arise in practice, and, in many cases, the examples can be used as a base for real applications.
The Win32 API is supported by Microsoft's 32-bit operating systems: Windows NT and Windows 95. There is no doubt that Win32 is an important factor for application developers, in many cases replacing UNIX as the preferred API for application programs targeted at the desktop and client/server systems. Many observers predict that Win32 will become the dominant programming interface, whereas others feel that UNIX and Win32 will coexist and each will find its own niche.
Regardless of the outcome of the operating system wars, many experienced programmers will want to learn the Win32 API quickly, and this book is designed to help them.
The first objectives are to explain what Win32 is, show how to use it in realistic situations, and do so as quickly as possible without burdening the reader with unnecessary detail. The book is, therefore, not comprehensive, but it does explain the central features of the most important functions and shows how to use them in realistic 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 Win32 API easy to learn using this approach, and I have greatly enjoyed developing Win32 programs despite occasional frustration. This enthusiasm will show through at times, as it should. This does not mean that I feel that Win32 is necessarily better in any sense, but it certainly has many attractive features.
Most Win32 books are designed for Windows 3.1 programmers and often concentrate on the user interface. These books spend a great deal of time explaining how processes, virtual memory, interprocess communication, and preemptive scheduling work. A programmer experienced in UNIX, VAX VMS, IBM MVS, or another high-end operating system-that is, nearly anything other than the Windows 3.1 Win16 API-will be familiar with these concepts and will be impatient to find out how they are implemented in Win32. Most Win32 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 core features.
Chapters are organized topically so that the features required in even a single-process application are covered first, followed by process and thread management features. This organization allows the reader to advance logically from file systems to security, memory management, and file mapping, and then to processes, threads, synchronization, and other Win32 system services. 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, appear last.
Within each chapter, after introducing the functionality area, such as process management or memory-mapped files, we discuss important Win32 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 disc provided with the book. Throughout, we identify those features supported only by Windows NT, as Windows 95 does not implement many advanced features. Each chapter suggests related additional reading and gives some exercises.
Chapter 1 is a high-level introduction to Windows NT and Windows 95, showing why you might need to learn about them. Chapter 2 compares UNIX, the C library, and Win32, with short file copy programs illustrating and contrasting each. Chapter 2 also introduces the Win32 programming style and conventions.
Chapters 3 and 4 deal with file systems, console I/O, and directory management. Unicode, the extended character set used by Windows NT, is also introduced here. Examples include sequential and direct file processing and a directory traversal program.
Chapter 5 introduces Win32's Structured Exception Handling (SEH) capability, which will be used extensively starting in Chapter 6. Many books defer SEH to later chapters, but by introducing it early, this book lets you use it throughout.
Chapter 6 treats Win32 memory management and shows how to use memory-mapped files.
Chapter 7 explains Windows NT security, showing, in an example, how to emulate UNIX-style file permissions. Security upgrades can then be applied to the examples as appropriate. Although security is used in the later chapters, feel free to skip this chapter if you are not interested in security.
Chapter 8 introduces Win32 processes and simple process synchronization along with file locking. Chapter 9 then shows how to use anonymous and named pipes for interprocess communication. Chapter 10 discusses threads, and Chapter 11 covers the various synchronization primitives: mutexes, semaphores, events, and critical sections.
Chapter 12 gives a brief introduction to some additional topics, including dynamic link libraries, and shows how to create in-process servers using DLLs. The Internet Server API (ISAPI) is used to illustrate these concepts.
Chapter 13 shows how to use overlapped I/O with events and completion routines. For file systems, this feature applies only to Windows NT, and you can achieve much the same thing with threads, so this chapter will be optional for some readers.
Chapter 14 concludes with a survey of two specialized topics: fibers and the registry. Beyond discussing these features, this chapter illustrates that readers now have the necessary information to learn other Win32 topics beyond the core system services.
There are three appendixes. Appendix A describes the programs on the disc and how to use them. Appendix B contains several tables that compare Win32 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 Win32 features, both basic and advanced, and the C library.
Within the text at appropriate points, we contrast Win32 style and functionality with the comparable UNIX and ANSI Standard C library features. Tables listing the comparable functions are 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, and labeled with a UNIX icon.
Exercises at the end of each chapter suggest alternative designs, subjects for investigation, and additional functionality. Some exercises are easy, and a few are very challenging.
All examples have been debugged and tested under Windows NT and, where appropriate, under Windows 95. For Windows NT testing we used versions 3.51 and 4.0, and although the bulk of the development was performed on single-processor, Intel-based systems, the programs were also tested on multi-processor and Digital Alpha 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-and, better still, fixes.
Numerous people have provided assistance, advice, and encouragement. It is conventional to say that the book would not have been possible without them; in this case, that would be an understatement. The Addison Wesley Longman editors-Ben Ryan and Mike Hendrickson-have patiently steered the book through the many stages from first concept to publication, and Sarah Weaver has been an excellent and helpful project manager. Betsy Hardinger, the copy editor, made many improvements. Alan Feuer, the series editor, deserves special and immediate thanks and recognition. Not only has Alan provided the normal encouragement and prodding, but his suggestion to develop UNIX-like commands as sample programs greatly improved my first clumsy examples. Students in the Technology Exchange Company's course 835, Win32 System Programming, which is based on this book, have provided invaluable suggestions. Readers who have made useful comments or provided encouragement at various stages include, in alphabetical order, Maury Bach, Ed Dekker, Peggy Harris, Shirley Kaltenbach, Joe Newcomer, Ali Rafieymehr, Edward Schiebel, and Larry Schmuhl. Hein van den Heuvel and Marc Slater of Digital Equipment Corporation arranged access to the Alpha and SMP systems used for performance tests in Appendix C. Elissa Armour prepared the manuscript with patience, skill, and professionalism. Dominic Chan and Allan Deary of Peritus Software Services, Inc., have encouraged this effort and made computing resources available for developing both the text and the example programs. Most importantly, my wife Linda is the one whose support has really made this book possible. It's been a wonderful 30 years together, and we look forward to many, many more.
Johnson (John) M. Hart
0201634651P04062001
"Overall, I feel that this book is an excellent learning tool for classroom-based, intermediate programming classes or independent study for a person with a prior programming background."
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.
To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:
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.
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.
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.
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.
If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.
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.
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.
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.
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.
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.
This site currently does not respond to Do Not Track signals.
Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.
This site is not directed to children under the age of 13.
Pearson may send or direct marketing communications to users, provided that
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.
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.
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.
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.
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.
Pearson may disclose personal information, as follows:
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.
Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.
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