Fully updated to reflect Win32 enhancements in Windows 2000 and Windows 98, Marshall Brain's classic guide remains the most effective way for developers to master Win32 services in real-world application development. Brain introduces Win32 files, directory and drive structure, NT processes and threads, synchronization mechanisms, network communications, Remote Procedure Calls, NT services, NT security, consoles, communications ports, accessing system information, and using DLLs to modularize programs. Each self-contained chapter covers a different API service, with functions demonstrated clearly in code examples. Brain also shows how multiple services can be integrated to create larger, more sophisticated applications.
Click here for a sample chapter for this book: 0130225576.pdf
One Hundred and Twenty-one Questions About Windows 2000 and 98. Compiling Code. Terminology. Error Handling. Handles and Objects. Using the Microsoft Documentation. Bugs in the 32-Bit API. Differences Between Windows 98 and Windows 2000.
The Possibilities. Overview. Opening and Reading from a File. Getting and Setting File Information. File Operations. Temporary Files. File Reading and Writing. Asynchronous File Operations. File Locking. Compressed Files. File Mapping. Conclusion.
The Possibilities. Getting Volume Information. Getting Drive Types. Getting Free Space. Getting Logical Drives and Drive Strings. Setting the Volume Label. WNet Functions. Conclusion.
The Possibilities. Creating and Deleting Directories. Getting and Setting the Current Directory. Searching for a File. Traversing Directory Trees. Combining Capabilities. Detecting Changes to Directories and Files. Conclusion.
The Possibilities. Introduction to Active Directory. Active Directory Architecture. Frequently Asked Questions. Conclusion.
The Possibilities. Introduction. Simple Examples. Using Threads in GUI Applications. Matching the Number of Threads to the Number of CPU's. Using Thread Local Storage. Thread Priorities. Other Thread Functions. Processes. Inheriting Handles. Interprocess Communication. Jobs. Conclusion.
Understanding the Problem. Four Different Synchronization Methods. Deadlocks, Starvation, and Other Synchronization Bugs. Wait Functions. Overlapped I/O. Change Functions. Integrating Synchronization into MFC Programs. Conclusion.
The Possibilities. Understanding Your Options. Mailslots. Named Pipes. Named Pipe Client/Server Systems. Connection with UNIX and Other TCP/IP Machines. UDP Connections. TCP Connections. Conclusion.
The Possibilities. The Basic Idea. Design Issues. Creating RPCs. Understanding RPCs at a High Level. Parameter Passing. Understanding the Code. Setting up a Name Server in the Registry. Manual Binding with Implicit Handles. An RPC Server for Mandelbrot Sets. Improving the Mandelbrot RPC Server. Explicit Handles. Context Handles. Common Questions. Conclusion.
DCOM Architecture. Components and Reuse. Location Independence. Connection Management. Scalability. Conclusion.
The Possibilities. Understanding Serial Communications. A Simple Communications Application. Getting Communications Events. A Simple Bulletin Board System. Flow Control. A Simple TTY Terminal Program. Other Communications Functions. Conclusion.
The Possibilities. Understanding Services. S ervice Choreography. The Simplest Service. Installing and Removing a Service. Displaying Dialogs from within a Service. Multiple Services in an Executable. Getting and Setting Configuration Information. Controlling Services. Enumerating Services. Placing an RPC Server in a Server. Conclusion.
The Possibilities. -Understanding the Terminology and Concepts of the Windows 2000 Security _System. Windows 2000 Security Vocabulary. Simple Examples. Securable Objects and Access Rights. Examining Existing Access Tokens and Security Descriptors. Privileges. Adding and Deleting ACEs. Impersonation. Conclusion.
The Possibilities. Raw versus Cooked Input. Simple Examples. Raw Input. Other Input Events. Other Capabilities. Conclusion.
The Possibilities. MMC Interfaces and Methods. ATL Snap-In Wizard. Conclusion.
The GetSystemInfo Function. Other System Information Functions. Getting and Setting Environment Strings. Shutting Down the System.
The Possibilities. Overview. Creating a Simple DLL. Understanding a Simple DLL. Load-time versus Run-time Linking. DLL Entry Points. Memory Models. Conclusion.
COM Fundamentals. Component Object Library. Summary.
COM+ Programming Overview. COM+ Application Overview. Developing COM+ Applications. COM+ Design Assumptions and Principles. Conclusion.
Frequently Asked Questions about Windows DNA. Microsoft Windows Distributed Internet Application Architecture. The Presentation Tier. Business Services Tier. Data Services Tier. Conclusion.
Registry. The Event Log. Time. Memory. Structured Exception Handling. Error Handling.
The Win32 system services are the innovative, cutting-edge capabilities that make Windows 2000 and Windows 98 interesting and exciting. Amid all of the media attention surrounding Windows 2000 and 98, you have probably heard and read about many of the modern capabilities that these operating systems contain:
The goal of this book is to show you how to use all of these different services in your own applications. This book contains hundreds of concise, clear, and easy-to-understand example programs and explanations. The examples show you how to access the system services listed above, as well as many others. You can use these examples directly, to understand the concepts. You can also drop the sample code into your own programs and then extend it to give your applications new and useful features.
By learning about the many and varied system services available inside of Windows 2000 and 98, you can make your programs much more interesting to the user. For example, if you learn about threads and then add multiple threads to your applications, the user gets a much smoother interface (see Chapter 6). Your program will also take advantage of multiple processors on machines that have them. If you add network support to your applications, the user is able to access network resources that are unavailable on a single machine (see Chapter 8). If you add modem support, you can use it to let the user dial into a remote system (see Chapter 11). Or you might use a modem to let the user dial a support line or registration system for a product that your company sells.
The goal of this book is to give you a thorough and clear understanding of the system services so that you can take advantage of all of the capabilities that Windows has to offer.
This book is designed for two types of people. If you are a devoted connoisseur or student of programming, the study of the system functions is interesting in its own right. It's fun to see what functions are available, and to try to think of ways to exploit those capabilities. One way to use this book is to simply browse through it and see what is possible. You can work with the examples and extend them in ways that you find enjoyable.
If, on the other hand, you are a programmer with a deadline, enjoyable entertainment is probably not your goal. You may have looked at the huge number of functions in the Windows API and found it discouraging. Where do you start? What you need is a set of useful examples and clear explanations that quickly solve your specific problems. You will find this book useful because it organizes concepts logically and provides the material that you need to master a specific topic very quickly.
If you are migrating from another operating system to Windows, this book will help you to quickly map your existing knowledge into the Windows framework. See Chapter 1 for a list of the 121 most common programming questions in Windows, as well as for the locations of the sections that contain the answers.
This book is organized by functional categories. For example, Chapter 2 talks about all of the functions that pertain to file input/output and file handling. Chapter 3 deals with disk drives. Chapter 4 discusses directories. Chapter 5 talks about the next-generation directory services, known as Active Directory in Windows 2000. Chapter 6 talks about processes and threads. You will find that each chapter starts with a general overview of the topic, followed by sections that describe and give examples for subsets of functions.
In many chapters you will find integrating examples that combine different capabilities from several chapters to create larger applications. Many of these larger examples form complete applications that you can use as starting points for new projects of your own.
Several principles guide the content of this book. The first principle is the most important and is therefore used throughout: it is simplicity. There is nothing worse than looking up a function, only to find that its example is embedded within sample code that takes three days to comprehend because it is 28 pages long. In all cases a function is first demonstrated in code that is as simple as possible so that you can extract the essence of each one very quickly. They may then be integrated into larger examples. In many cases you will look at the example code and say to yourself, "This is easy!" That is exactly the intent. If the book makes everything look simple and easy for you, then it has accomplished its goal.
The second principle driving this book is the idea of functional families. Functions in the 32-bit API very rarely exist on their own-it is far more common to find small collections of functions that relate very closely to one another. For example, the ReadFile function reads from a file, but you must open the file with CreateFile before you can read from it and then remember to close it with CloseHandle afterwards (see Chapter 2). These functions belong to a family. In this book you will generally find small groupings of functions described as logical units.
The third principle in this book is that of currency. The Windows API has been around for some time, and when you look at it you will find that there is a certain amount of layering. The documentation will often say things like, "this function is retained for compatibility with version 1.8, but has been superseded by function xyz." This book deals only with the current functions, and leaves the superseded ones to die in peace.
The last principle guiding this book is independence. Each chapter in this book is as stand-alone as possible, so that you can jump around in the book as you please. In cases where material from other chapters is important, you will find references to the related sections.
This book makes no assumptions about your former knowledge of systems programming in Windows or in any other system. Its only real assumption is that you know C and/or C++. You will find that the example code can be divided into two categories:
If you are a C programmer with no C++ experience, you will have no trouble understanding the console programs. The only unusual thing you will see is code that looks like this:
char s100;// Prompt the usercout << "Enter a line of text: ";// Read a line of text from the usercin.getline(s,100);// Echo the user's input to stdoutcout << s << endl;
This code declares a character string s, and then uses "cout <<" to output a prompt to the user. The "cin.getline" statement reads a line of text from the user. The final "cout" statement echoes the line. The book Visual C++: Developing Professional Applications in Windows 95 and NT using MFC, by Marshall Brain and Lance Lovette (ISBN 0-13-305145-5), contains an extensive C++ appendix to help you get started with the language if you are interested. It will also help you understand the MFC code.
The diskette included with this book contains the source code for all of the examples in the book, as well as the source and data for an on-line indexing program. The index is broken down by sections and includes every word found in the manuscript.
To use the index, follow the directions in the README file on the disk to compile the program. When you run the index, you will see a display that contains an edit area, three buttons (Help, Search and Quit), and a list area. Any words that you type in the edit area are used to search for appropriate sections. For example, if you want to find out how to create a DLL entry point, you would type "DLL entry point" in the edit area. Press the "Search" button to begin the search. The index program will list all sections that contain all three of those words. Enter as many words as you like to home in on what you want. Word matching is exact and case-insensitive. If a word does not appear in the book, the program will tell you.
There are many cases where an exact match does not work well. For example, there may be a section that contains "thread" and "create" but not "creating" and "threads," so if you enter the line "creating threads" on the edit line you get no matches. You can use the "*" wild card character at the end of a word to solve this problem. For example, by entering "creat*" the system will use OR to gather together all words with the root "creat" ("create," "creates," "creation," etc.). You may want to get in the habit of using the wild card character at the end of all words: "creat* thread*," for example. This often yields more helpful results.
If an obvious word seems to be missing from the index, try to find it in the book to make sure you are spelling it correctly. For example, "resize" is spelled "re-size" in the book, and you need to spell it the same way.
Each chapter in this book talks about a different service in the 32-bit API. Chapter 1 contains a list of the 121 most common questions about the system services, and it will help you to quickly find material that interests you. The list below summarizes the different chapters in the book to help you with browsing.
One thing about Microsoft is that it never stands still for very long. Its compilers and libraries are constantly changing. One of the goals for this book is that its code be as compatible as possible with existing and future releases of Microsoft compiler products. Another goal is to give you "investment-grade" knowledgeknowledge that does not lose its value over time, and that is transferable between as many different platforms as possible.
As things change, however, you need a way to get updates and corrections. You may also have questions, comments or suggestions for improving this book. If so, we would like to hear from you. You can use our free E-mail information server to get updates and supplements to this book. You can also send questions and comments via E-mail or U.S. mail. Please see Appendix B for instructions.