Windows System Programming, Edition 4
Published by Addison-Wesley Professional. Part of the Addison-Wesley Microsoft Technology Series series
Download the Examples file (Version 1.12, January 24, 2011)
At last, Edition 4 is complete! It's taken longer than expected, but the results have been worth the effort. There are many improvements, but I've also been able to retain the basic approach and style of Editions 1-3. I hope you enjoy it and will look forward to hearing from readers.
John Hart, January 18, 2010
About Edition 4
Here is the link to the informIT Windows System Programming, Rough Cuts, 4th Edition page
Edition 4 is a significant update of Edition 3 (2004) and its predecessors. I've reworked all the examples, added new examples, added lots of new material, and corrected misleading and (at times) incorrect statements. Here's a summary from the preface:
Changes in Edition 4
Edition 1, titled Win32 System Programming, was published in 1997 and was updated with Edition 2 (2000) and Edition 3 (2004). Much has changed, and much has stayed the same since these previous editions, and Windows has been part of ongoing, rapid progress in computing technology. The outstanding factors to me that explain the Edition 4 changes are the following:
This fourth edition presents extensive new material along with updates and reorganization to keep up with recent progress and:
- The Windows API is extremely stable. Programs written in 1997 continue to run on the latest Windows releases, and Windows skills learned now or even years ago will be valuable for decades to come.
- Nonetheless, the API has expanded, and there are new features and functions that are useful and sometimes mandatory. Three examples of many that come to mind and have been important in my work are (1) the ability to work easily with large files and large, 64-bit address spaces, (2) thread pools, and (3) the new condition variables that efficiently solve an important synchronization problem.
- Windows scales from phones to hand held and embedded devices to laptops and desktop systems and up to the largest servers.
- Windows has grown and scaled from the modest resources required in 1997 (16MB of RAM and 250MB of free disk space!) to operate efficiently on systems orders of magnitude larger and faster, but often cheaper.
- 64-bit systems, multicore processors, and large file systems are common, and our application programs must be able to exploit these systems. Frequently, the programs must also continue to run on 32-bit systems.
- Covers important new features in Windows 7, Vista, and Server 2008.
- Demonstrates example program operation and performance with screenshots. (Author note: I think these sreenshots really help to understand example usage and also work well to show comparative performance)
- Describes and illustrates techniques to assure that relevant applications scale to run on 64-bit systems and can use large files. Enhancements throughout the book address this issue.
- Eliminates discussion of Windows 95, 98, and Me (the “Windows 9x” family), as well as NT and other obsolete systems.
- Program examples freely exploit features supported only in current Windows versions.
- Provides enhanced coverage of threads, synchronization, and parallelism, including performance, scalability, and reliability considerations.
- Emphasizes the important role and new features of Windows servers running high-performance, scalable, multithreaded applications.
- Studies performance implications of different program designs, especially in file access and multithreaded applications with synchronization and parallel programs running on multicore systems.
- Addresses source code portability to assure operation on Windows, Linux, and UNIX systems. Appendix B is enhanced from the previous versions to help those who need to build code, usually for server applications, that will run on multiple target platforms.
- Incorporates large quantities of excellent reader and reviewer feedback to fix defects, improve explanations, improve the organization, and address numerous details, large and small.
I've also taken care to make program appearance be much more uniform than in previous editions. For example, I've consistently used the "camel notation" for variable names (this is one of many possible conventions; I found the camel notation to be convenient, and sticking to some convention is better than none at all). I believe that changes of this nature will simplify code understanding.
One more point: The technical reviewers did an incredible job. They suggested numerous improvements of all sorts. It took a lot of work to address all the suggestions, but the effort was definitely worthwhile and will add value for readers at all levels. The reviewers names and a full acknowledgement are in the book's preface.
From the Back Cover
Here is the book's back cover copy, which explains a bit more, but in the third person:
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 screen shots.
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
- Techniques to improve program reliability and performance in all 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
- New Windows performance-enhancing API features available starting with Windows Vista, such as slim reader/writer locks and condition variables
Windows Versions: Vista, 7, Server 2008, Server 2003, and Windows XP
Edition 4 assumes that you are using or targeting a "current" Windows version, and the book freely exploits new Windows features. In particular, Windows Vista and later Windows versions (Server 2008 and Windows 7) support useful new API features and also provide improved performance in some cases. These three versions use Windows NT kernel version 6, or "NT6" for simplicity (Microsoft does not use the term "NT6", but it's a convenient term).
Nonetheless, Windows XP and Server 2003, and even Server 2000 (based on Windows NT kernel version 5, or "NT5"), will be around for some time, and Vista adoption has been slow (Windows 7 may have a higher adoption rate). Therefore, nearly all programs will operate under NT5. Exmaple programs that depend upon NT6 will issue an error message if you run them on an NT5 system. However, there are workarounds in some cases.
The NT6 advantages are most significant for multithreaded programs (impacting Chapters 9, 10, and 14). Thus, NT6 provides:
- Condition variables, which correctly and conveniently implement the critical section model and eliminating problems with the PulseEvent function.
- Slim reader/writer (SRW) locks (SRW) which are faster than CRITICAL_SECTIONs.
- Thread pools
- Enhanced cancellation functionality
Furthermore, NT6 asynchronous I/O performance is much better than on NT5. You do not need to make any code changes to realize this performance improvement.
From the point of view of the Windows API, NT6 provides numerous advantages. I say this fully realizing that many users, for very good reasons, will stick with Windows XP for some time. Furthermore, if you are developing applications for a wide audience, you will need to assure that the applications run correctly, if not optimally, on NT5 systems.
The Examples, Visual Studio, and Open Source Tools
The Examples file, which you can download from this site, contains complete programs for all the examples in the book. Numerous adddtional examples, generally mentioned in the book, illustrate addtional points or exploare alternative methods to solve problems.
All the examples are provided as Visual Studio solutions, in both Visual Studio 2008 and Visual Studio 2005 format. The projects convert easily to Visual Studio 2010 (RC) form. However, I'll add the new solutions after the VS 2010 planned for April 2010.
Some Edition 3 readers have reported success using open source development tools, such as gcc and g++ in the Gnu Compiler Collection (http://gcc.gnu.org/). Readers interested in these tools can look at the MinGW open source pro ject (www.mingw.org),
The examples have been tested, and performance comparisons performed, on all current Windows versions, in both 32-bit and 64-bit form where appropriate.