Home > Store

Win32 System Programming

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

Win32 System Programming

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 1997
  • Dimensions: 7-3/8x9-1/4
  • Pages: 384
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-63465-1
  • ISBN-13: 978-0-201-63465-5

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.



0201634651B04062001

Sample Content

Table of Contents



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.



2. Getting Started with Win32.

Win32 Principles.

The Standard C Library: When to Use It.

Example: A Simple Sequential File Copy.

Summary.

Exercises.



3. Using the Win32 File System and Character I/O.

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.



4. Direct File Access and File Attributes.

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.



5. Structured Exception Handling.

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.



6. Memory Management and Memory-Mapped Files.

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.



7. Security.

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.



8. Process Management.

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.



9. Interprocess Communication.

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.



10. Threads and Scheduling.

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.



11. Win32 Synchronization.

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.



12. Dynamic Link Libraries, In-Process Servers, and the ISAPI.

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.



13. Asynchronous Input/Output.

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.



14. Other Topics: Fibers, the Registry, and Beyond.

Fibers.

The Registry.

Beyond the System Services.

Summary.

Exercises.



Appendix A. Using the Sample Programs.

Disc Organization.

Include File Listings.

Additional Utility Programs.



Appendix B. Win32, UNIX, and C Library Comparisons.

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.



Appendix C. Performance Results.

Test Configurations.

Performance Measurements.

Running the Tests.



Bibliography.


Index. 0201634651T04062001

Preface

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.

Audience

  • Anyone who has experience programming in UNIX or in an operating system other than Windows 3.1 and who wants to learn about Win32 quickly.
  • Programmers and software engineers who must port existing applications, often in UNIX, to Win32 for operation under Windows NT or Windows 95. This book contains many comparisons between Win32, 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 Win32 terms.
  • Programmers who are developing servers or other systems in which management of resources such as processes and threads is of primary importance and in which the user interface is of secondary importance.
  • 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 Win32 functions are used to create useful applications and to solve common programming problems.
  • Computer science students at the upperclass undergraduate or beginning graduate level in courses covering systems programming or application development. This book would be a useful complementary text to a book such as W. Richard Stevens's Advanced Programming in the UNIX Environment (see the Bibliography) so that students could compare Win32 and UNIX.

Organization

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.

UNIX and C Library Notes and Tables

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.

Examples

The examples are designed to do the following:
  • Illustrate common, representative, and useful applications of the Win32 functions.
  • Correspond to real programming situations encountered in program development, consulting, and teaching.
  • Emphasize how the functions actually behave and interact, which is not always as you might first expect after reading the documentation.
  • Grow and expand, adding new capability to a previous solution in an easy and natural manner and exploring alternative implementation techniques.
  • Frequently implement UNIX commands, such as ls, rm, and sort, showing the Win32 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 Win32 features. Appendix C contains the results of these performance tests.

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.

Acknowledgments

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
jmhart@world.std.com



0201634651P04062001

Updates

Errata

Click below for Errata related to this title:
Errata

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