Windows 2000 System Programming (1)

zhaozj2021-02-08  202

Chapter 1 Direct Overview Windows 2000

I don't hidely, I am a sci-fi fan. However, I think the science fiction description in reality is ridiculous. Although I can accept the fact that there is a biosphere and galaxy empire, it can even accept super-speed interstellar aircraft, but I can't accept it easily to communicate with aliens. Of course, in Star TR E K, all aliens speak English. In fact, a very small number of science fictions involved how the first contact alien culture will. Usually the aliens are English through radios and television, or they rely on a powerful translation machine. Regardless of the way people can't see, it will not hinder the progress of the story. Consider communication between people. No matter who communicates, no matter what topic, the communication between the two is self-evident, do not need to express it, what example? Look at the following quirky but correct sentences: "I Saw the Grand Canyon While Flying to New Yo RK." (I saw Grandcanyon in New York.) You I know that the speaker is flying to New York, and I saw Grand Canyon (Grand Canyon). But from the grammatical understanding, this means, the Grand Canyon Grand Canyon is flying to New York, and I saw it! Of course, it is nonsense, because everyone knows that Grand Canyon Grand Canyon will not fly. Aliens (or computers) don't know what Grand Canyon is. It is because everyone understands some common sense because everyone knows some common sense. When you cross the world's cultural boundaries, the problem is worse. Many years ago, the real news published in the British newspaper was as follows: "British Left Wa Fresh" (British Left Titrament) (British Left Titrament) The situation in the F Alkland Islands.) Usually, Americans will be surprised, why British forgets why Breakfast is worth reporting ( They think the British forgets to eat waffles in F Alklands). However, if you understand the incidents that occurred in the UK, you will understand that British Left is a political parties. Headline is saying that they can't accept the situation in the F A L K L a N D Islands. Is it crazy about the British newspaper editor? of course not. They simply believe that readers already have these knowledge, and most Americans are not. The same concept is also correct in any complex programming. When you discuss programming issues with others, you should also imagine them to understand these issues. If you stop one person on the street, I will ask why P R i n t f will fail when it is connected to the code. Unless you encounter C or C programmers, otherwise the opponent is absolutely unity.

1.1 new language

Assume that you are a C programmer at this moment. You know some basic knowledge as other C programmers. If the boss assigns you to solve the problem of 2 0 0 0 in C O B O L, no one wants you to start this work well. The programmer of the C O B O L language has the different knowledge foundations of C programmers. C O b O L programmer and C programmers are often very difficult, everyone is thinking. However, due to some reasons, the operating system cannot share this luxury. The bosses seem to expect you to easily, and do not turn around U N i x, V M v S, M s - D O S and Wi N D O W s. If you are good at a version of Wi N D O W S, this is especially true. But in fact, these tasks have a large phase. If you have learned the program design under Windows 3.0, you can slowly master Windows NT or Windows 2000, but this is also the result of effort. If you use Windows 2000 from other operating systems, the situation will be quite painful. As a older with u n i x, I have witnessed many friends to turn from U N i x to Wi N D O W s. They usually complain how Wi N d o w s is so bad. In fact, 3 2 versions of Windows and U N i X are not completely different. But there is a difference. Drop the original basic knowledge and restart it, it is really difficult. If someone requested "Creating a new process", then the authority of u n x, considering the Fork instead of C R e a t e p R O C e s S. Of course, you can find C R e a t p r o c e s s in help, but just travel abroad and use a stupid foreign language common manual, this will have a few points, but it is not comfortable. So you need some basic knowledge. The purpose of this chapter is to enable everyone to start from the same starting point. Here will show some of the contents that should be understood (perhaps already known) about Wi N D O W s. This way, you add basic information on the rest of the books that need to be understood. 1.2 Wi N d o w s simple history

If we go back to create a company and open up a Wi N D O W S operating the system market, we may also make a career. Wi n d o w s is controversial. Only companies such as M i C R O S O F T can support Wi N D O W s until a practical thing is developed. The problem with Wi N D O W s is not all the negligence of M i C R O S O f T. Don't forget, the computer only has a slow processor, a wide and narrow bus and a small memory. Wi N D o W s can be lucky. Just the timing is not yet mature. I N t e l 3 8 6 is a first P C compatible processor that handles systems that really like Wi N D O W S. M i C R o s O f T quietly launched a product named Wi N D O W S / 3 8 6 and showed its advantages. This is the first version of Wi N D O W S, which is well running, and is deeply loved by most people. Soon after Wi N D O W S / 3 8 6, M i C R O S O f T launched Windows 3.0. This is the first commercial version of Windows. This version is not a sharing problem, but the problem is not enough to affect people's purchase of this product. Due to the large number of potential purchases, software companies have rustled the programming of Wi N D O W s (usually, called applications). Soon, Microsoft released Windows 3.1. This version not only repairs many of the program errors in Windows 3.0, but also introduces many important new features. Many programmers first learned Wi N D O W S based on Windows 3.0 or 3. 1. Although users like these versions of Wi N D O W s, most programming people don't like them. These versions of Wi N D O W S have also retained many burdens left behind. If memory management is defective, the segmented storage mode is often annoying, and multitasking is still rough and requires all programs involved in all programs to work. If any program does not cooperate, the entire system will crash. 1 6-bit system roots with a port code from U N i x or other 3 2-bit operating systems. In addition, the market pressure requires the application of Wi N D O W s, that is, the application provided by the programmer. No matter how bad, this is the starting point of most programmers. M i C R O S O f T has also issued different versions of Windows 3.1, including Windows for Workgroups 3.1 and 3. 11, Windows 3.11. From the perspective of development, these are not important.

1.2.1 Windows NT However, the real move is that M i C R O S O f T decides when to develop Windows NT. Because M i C R O S O f T is convinced, if it is not limited by the previous processor, Wi N D O W s will be more excellent. At the same time, it also knows that when networking and distribution processing, Wi N D O W S cannot compete with U N i X. At that time, things that made M i c R o s O S were anxiety were: Other operating systems or microprocessor structures were squeezed with Wi N D O W S and I N T E L hardware platforms. M i C R O S O f T is confident that only the flexibility of N t, which is not affected by the flexibility of other operating systems to run in different hardware platforms. The release of N t can be said that it is not angry. It is far more than the hardware environment of people at the time. In the case of 1 6 m b memory (and there are few memory more than 8 m b), only the minimum performance is obtained. At the same time, there must be C D -R O m to install N t, and at that time, very few people have a CD-ROM drive (in fact, I bought the optical drive is completely required to install NT). Even if there is a hardware environment required to run, there are still two major issues: lack of equipment support and lack of applications. Therefore, there are only a few P C machines in the world to operate N t, and most of them operate Wi N D O W S 3. 1. The developers of hardware and software lack support for N t. Of course, N t can also run the program of most Windows 3.1, not all programs can run. Why do you want to buy N t, isn't it just to run Windows 3.1? In particular, N t requires more costs and requires expensive hardware upgrades. However, M i C R O S O f T still supports N t (like the development of Wi N D O W S products), and silently improve N T on several versions. In addition, M i C R O S O f T knows that the third-party developer must be attracted to the application of N t.

1.2.2 Windows 95 Solving the answers to the above problems is Windows 95. M i C R O S O f T Introduces New Product Windows 95 replacing Windows 4.0. M i C R O S O f T wants Windows 95 as Windows NT Lite (experience its characteristics, not its alternative). However, the Windows 95 is actually more like Windows 3.1. The key to Windows 95 is its name support as a programming interface as Windows NT. So why don't you write program code running on Windows 95 and N T? This will enable the software that runs on N t, isn't it? To achieve this purpose, M i C R O S O f T is to do is to bring every user of Windows 3.1 to Buy Windows 95. This forms some design choices, which are difficult to adjust in other respects. This is not only a very good strategic work, but the number of 3 2-digit applications surged. So, what is the distributors of N t products? Is this not a good time for N t to open the Windows 3.1 market? However, it is not. Windows 95 Application Interface (Application Programming "is just a subset of the Windows NT application interface. If you understand this, you can write the code that can run in both platforms, but unless you are planning, Otherwise, the code writes is reliable. In a technique, Windows 3.1 API is called a P i of Wi N 1 6, while other versions use Wi N 3 2 A P i. However, Wi N 3 2 under Windows 95 is not entirely on Wi N 3 2 under Windows NT. However, from the Windows 3.1 program to the new Windows 95 / NT API seems suddenly. Many programmers are incredible. For those who are still in Windows 3.1, M i C R O S O F T develops products called Wi N 3 2 S for developers. If the library of Wi N 3 2 S is used in the program, a small Windows NT command subset is formed. Wi N 3 2 S library automatically converts it to a Windows 3.1 command. In theory, part of the code can run on Windows 3.1, Windows 95, and Windows NT. In fact, Wi N 3 2 s failed. Part of the reason is that it is unstable, and the reason is that the actually constituted command subsets are very small, and there are too many restrictions on developers. Although there is still a few developers in improving Wi N 3 2 S, the final M i C R o f t or gives up. All in all, the strategy of M i C R O S O F T is very successful. Applications that can also be running on the N T Windows 95 developed everywhere. Suddenly discovered that people can run the real 3 2 programs on Windows NT. 1.2.3 Other aspects

At the same time, hardware technology development is also quite fast. The processor of the Pentium (P e n t i u M) has become a standard, and the price of memory has fallen rapidly. High performance video cards and printers have also have 8 m b of random memory (RAM), and many people's P C machine is 6 4 m b or greater R a M. These P C machines are sufficient to meet the requirements of running N t, so many people have begun to turn to use NT 3.5 or NT 3.51. The decline in the multi-processor's motherboard price is more excited to use N t to turn it. (On the multiprocessor system, running Windows 95 is a waste because Wi N 9 5 uses only one processor at any time) I N TE E R N e T 's booming more excited to use N T interest. N t is a quite a good network server platform, and most importantly, M i C R O S O f T contains I N t e R n e T tool in the N T server package. The only problem with Windows NT 3.51 is that from the user's perspective, its appearance and operation are too constant. Windows 3.1. Many users prefer Windows 95 interface style, plug and play, and other features that apply only to Windows 95. The release of Windows NT 4.0, bringing N t users more this (and some new features). For Windows 2000, M i C R O S O f T brings more users desired Wi N D O W S feature (such as supporting multiple monitors), and has added a lot of new tools for programmers. Today, most (not all) home users use Wi N D O W S9 5 or Windows 98. Most companies, developers, and super users (nor all) are running Windows NT and may turn using Windows 2000.1.3 Wi N D O W S version

Each version of Wi N D O W S has a different style. Most cases, programmers don't care which version they use. The main difference between different styles is the additional software and license number of M i C R O S O f T on the disk (like collaborative users allowed). Single desktop user's preferred is Professional Edition. It contains all functions required to use Wi N D O W s as a personal operating system. You can even use a professional version to constitute a small network. If you want Wi N D O W S run on a network or WE B server, you should select Server Edition. Server products have several versions as needed (for example, Site Server Provides M i C R O S O F T Personalization System and tools for large-capacity Web sites). Finally, Windows Advanceed Server and Datacenter Server make programs potentially address larger virtual space. These special versions of Wi N D O W s provide advanced networking features and support for additional multi-process processes.

However, as a programmer, there is no truly difference between these versions of Wi N D O W s. You can use the same method to do the same call using the same method. If you rely on additional components (or limitations of 3 G B virtual memory), you may need a special version, but usually, it is not necessary to run on a platform that must be run on which Wi N 3 2 platform.

1.4 Wi N D O W S architecture

From the perspective of programmers, Windows 2000 provides a fairly simple environment. Each program has an address range from 0 to 2G B storage space. Of course, most of the programs do not use this space, indeed, today is not that all systems have such a plenty of hard disk space and physical storage space. But this is not a problem because Wi N D O W S is only assigned its true storage space when the program is used. The address is from 3 2-bit integer values ​​from 0 to 4 G B (although only 0 to 2GB is valid). You don't have to worry about the use of the old version of Wi N D O W s segmentation structure, track memory or other weird things. Incidentally, the P e n t i m processor allows addressing to 4 G B space. However, the operating system retains the highest limit on 2 G B. Can the operating system really use so big space? No, it is possible to run the processor of Wi N D O W S with 2 G B user program space and 2G B operating system monitoring programs. So this mode is very good to match the microprocessor. Windows API is a standard interface of the system. We can form a call command for the operating system, and the operating system is actually stored in the system dynamic link library (DLL). If other operating systems are used, these commands are different from it, but the function is the same. These features include allocating storage, open files, and more. These features are mainly used to write programming languages ​​(like C ). You will use the structure in the program language to implement the above functions. For example, you probably call C R e a t e f i l e in the Windows API, and the F o P e n in the C library will call. On the other hand, C R e a t e f i l e can achieve certain functions that F O P e n cannot be processed. If you have a prior prior Wi N D O W S programming experience, you will find a bit of a difference between the commands of these functions. Many functions are the same as the call functions in Windows 3.1 and earlier. And there are some subtle differences. Sometimes M i C R O S O f T changes the name of the command to indicate that its parameter or return value is different. Common changes to names are E x at their tails. Thus, G E T C U R E N T P O S I T I O N is used in Windows 3.1, and G E T C U R E N T P O S I T I O N e x is used in Windows 2000 (or N t). What is the difference? When two 1 6-bit word representation of 3 2-bit word return value, G e t c u R R E N T P O S I T I O N returns to the currently described position. The g e t c u R R E N T P O S I T I O N e X returns two 3 2 digits in the pointer structure transmitted by the change. These functions have the same purpose, while Wi N 3 2 variables operate at 3 2. An additional change occurs in any of the functions of the receiving string. N T and Wi N 2 0 0 0 do not use a N S i string. Instead, they use 1 6-bit characters called U N I C O D E (more and more). However, most procedures use A N S I (or considered an 8-bit A S c i i character). Therefore, there are two cases each function that receives a string: one gives a A n S I string (and converted to U N I C O D E), and the other directly receives the U N I C O d E string.

For example, consider the function M e s S a g e b O x for Windows 3.1. Everyone knows that this function pops up a dialog box with a text string, and Wi N 3 2 does not have this function. However, it has M E S S A g E B O X A to give a A N S I-Cylindrical and M e s A g e B O X W Treatment u N i C O D E. However, the document also references M e s A g e B O x. This is because the C compiler and many other tools choose the correct result according to the priority of U N i C O D E. In the C program, when references M E S S A g e b O x, the extended extension is used as ME E S A g e b o x W macro based on the command to the compiler. Of course, this means that the error information of the compiler involves which function will be rejected, such as M e s A g e b O x A. 1.4.1 actual situation

The Wi N D O W S architecture is discussed in the following section. This section is very small. In fact, these programs that belong to Wi N D O W S are false. Windows 2000 (and Windows NT) does not actually operate Win32 API. Use a P i s special set, which includes execution programs (E X E C U T I v e). M i C R O S O f T did not disclose the document of the program, but it is indeed a basic set, and the M i C R O S O F T and its authorized users can be used to build A P I of the operating system. These executives perform all operations. However, the user does not call the execution program directly, but calls a subsystem. The subsystem provides personalized programs. For example, the Wi N 3 2 subsystem performs the executor of the G E T C U R R E N T P O S i T I t I O N e x and M E S I t I O N e x and M E Ss S A g E B O X A function, and calls the execution program that works. There are other subsystems (for example, a subsystem of poor P O S i X). NT 4 Previously, Wi N 3 2 subsystem is a separate module like other subsystems. However, when NT 4 and Wi N D O W S2 0 0 0, Microsoft realized that almost all programs actually use Wi N 3 2 subsystems. Therefore, in the N-version now, Wi N 3 2 subsystem is actually part of the execution program. This is nothing difference to application programmers, just faster. Under the execution program is the hardware separation layer (HAL) program. This software is even removed by ordinary programmers. This code knows how to perform all machine-specific tasks required for Wi N D O W S. So if you want to transfer Wi N D O W S into other types of computers, you only need to compile Wi N D O W S and write the H a L of the customer. Of course, in order to obtain all code and documentation, the consent of M i C R O S O F T must be obtained because M i C R O S O f T does not disclose the H a L (or Wi N D O W S source code). For single processors or multiprocessors, there are different H a L. For different machine architectures, H a L is also found in Power PC.

1.4.2 Wi N 9 5 and Wi N 9 8

Windows 95 and Windows 98 (with Windows 9X) How to describe this image? As mentioned earlier, Windows 9x is more like Windows 3.1 instead of Windows NT Lite. Although most of the WIN32 API commands are provided in Windows 95, most of them have not much stronger than Wi N 1 6 copies. Usually, there is also an exception, and if you don't do it in Wi N 1 6, it cannot be implemented in Windows 95 or 9 8. At first, this seems incredible. Why is the new technology have matured (Windows NT has been developed successfully), and M i C R O S O F T still releases new technology-based products? The answer is the market. A key target of Windows 95 is to spur the development of 3 2 digits. Thus, almost all users of Windows 3.1 have to turn to use Windows 95. Otherwise, Windows 95 will become a victim of another Windows NT - there is no powerful system for the application. M i C R O S O f T Write the Wi N D O W S - O N - Windows (WOW) module to run Windows NT to run Windows 3.1 program and amazing. Many important issues use the Win16 API defects and unpublished features. These programs will fail when W O W is running, and W O W is operated according to documentation. Make W O W really become Win16 API is tricky, so M i C R o s O F T is to retain W O W to make them do what should do. If the program is unable to run, there is a defect. This means that some Windows 3.1 procedures cannot run on N t. For Windows 95, no one is ready to adopt W O W. Home users are unlikely to update their machines, even if they doubt that some programs will not be able to run. So M i C R O S O f T requires copying Wi N 1 6 subsystem into Windows 95. Microsoft uses an obvious solution: uses an existing Wi N 1 6 subsystem. This guarantees all existing Wi N D O W S3. 1 software actually runs under Windows 95, and the old Windows 3.1 driver can work. M i C R O S O F T Remove the program part of the 32-bit code, but is merely a small portion (especially font translation and memory management). So, how will Windows 9X as 3 2? Since it contains Win32 API, it converts Wi N 3 2 command to Wi N 1 6 command (more like Wi N 3 2 S product). Due to this measure, many N T characteristics do not exist in Windows 9x. Other features are also different in Windows 95 and N t. In order to adapt to Wi N 1 6 programs, memory settings are also different. The book is not to describe Windows 95 (or extend to Windows 98). However, it helps to understand how to fit Wi N D O W s 2 0 0 0. Don't care about Windows 95/98, but you'll learn significant differences from N T families.

1.5 Characteristics and Differences of Wi N D O W S

If you are used to earlier versions of Wi N D O W s, or different types of operating systems, we will find strange features about Wi N D O W s 2 0 0 0. You don't have to be amazed for this, but you need to get used to it. Of course, we have no pre-arrangement, just explain how Windows 2000 works.

1.5.1 multi-tasking processing and thread processing

If you use U N i x, use the multi-task processing of Windows 2000, may have a feeling. The reason is that the u n i x (or other operating system) has different ways to handle multitasking, but many terms are the same. When running the program in Windows 2000, you can create a process, which is not surprising. Surprisingly, the operating system does not have a progress table of the process. The process has an open file, memory, or other resource, and also has a thread. What is thread? The thread (T H r e a d) is a record of a set of processor registers. It understands where to perform the code, where local variables are placed. Wi N D O W S Arrange the progress of the thread, just like twice. What is the difference between the progress of the process and the schedule process? That is, there is only one thread every process. However, what is the idea how the main thread creates another thread? The thread may create more threads again. It is important that Wi N D O W s is scheduled to schedule the progress, not the progress of the process. Each thread is running through a thread from other processes. So, what is the difference between threads and processes? It is very simple to belong to all threads that are easy to communicate because they share memory and other resources, and threads that belong to different processes are not easy to share data or communications. Indeed, they can communicate, but the method of communication between processes is required. 1. Delivery for previous U N i X programmakers, and additional difficulties are lack of derived (F O r k). In u n i x, the derived command copys the current process. Two processes are the same, each with a private copy of a program data. Usually, after derived, the execution (E x E c) is called. This loads a new file into a new process to remove the copy of the original process. For the C R E A T E P R O c e s S function of Wi N 3 2, as a single command, derived and execution is the same. But what will happen if you want to copy a process and save two replica? Wi N D O W s is not easy to implement. Why is this important? Suppose you have a program, trying to optimize the production of plastic balls. This is an example because it is more economical to produce plastic balls in special order. In other words, it is assumed that there must be three plastic products of A, B, and C to meet orders. If you are produced in the order from A to B to C, two tons of plastic will be wasted. why? Because each time you have to change the production of plastic products, there is a chemical mixture residue in the production process, which will cause some waste. But when the B product is more similar to the A type of products, what is the difference between the A-type product and Class C product does not have too much chemical nature? Then, when producing B products first, then produce A products, when regenerating C products, perhaps only a waste of 5 0 0 pounds. For this assumption, the first step is to read all the order and the current list of products and match each other. The rest is to process themselves. Now, your program wants to try several optimized strategies. Every time I try a policy, the different U N i x programs can be derived many times, create new processes for each optimization method. Each new process gets a private copy of the data collected at the first runtime. Finally, the primary process will test the results and decide which method is best. This will be difficult to do in Windows 2000. You can start a new process using C R e a t e pr o c e s s, but by default, there will be data with the old program. Indeed, you can use a shared storage area, even a file, but it is not so simple. How to use a thread? This is also a possibility.

However, if the optimization is changed, it is not feasible because all threads share the same variable. Take the derived as an example, each step is automatically owned by a private data copy. Each process will change the variable without affecting the relevant process. Interestingly, due to the ability to perform derived power for the PO I X subsystem. However, there is no way to access the derived process of Wi N 3 2. Please note: Lucent Technologies's David Korn already supports Win32 (U / WIN) P O S i X library (see w w w. R e s e a r C h. A t t. C O m / s w / t o L s / u w i n /), the rest is to implement derived. It is reported that the library uses C R E a TE E P R O c e s S to combine special startup code, which copy all the data of the inter-process communication method. It may have a lot of work, but it is actually quite good. 2. Windows NT with Windows 2000 on Windows 3.1

Even if you are familiar with Windows 3.1, you must also recall more multitasking. Of course, there is no thread in Windows 3.1, and each program run is a process. Since the process shared memory and other resources under Windows 3.1, they are actually more like Wi N D O W s threads. Another problem is how the program waives the control of the processor. Under Windows 3.1, the program executes one of them calls a few system functions (GetMessage, PeekMessage or Yi E L D). At this point, Wi N D O W S selects the abort the program and restores the other. This technique of collaborative multitasking is simply executed and released, while programmers don't have to worry about deadlocks or resource competition. As long as you don't call any special functions, you don't have to worry about the resources being used by other programs. The disadvantage of this solution is that if the program does not call these special functions, the system will lock. This is why Wi N D O W S3. 1 does not have the reason for the S L e e p command. If the program is suspended without a process message, the rest of the system will hang. Wi N D O W S uses a predetermined multitasking. It is also possible to sleep by performing some commands. However, if these commands are not executed, Wi N D O W s is finally in sleep state. This is a good thing, right? This is the case in most cases. It prevents crashing due to run error programs. Also make the system make faster responses to users. But for programmers, this increases the additional burden. Suppose there are several programs share an error login file. In Wi N D O W S, you can open the file, override the data and turn it off. As long as any special system command is called, you will know that there is no other program to open this file (because there is no other program to run). WINDOWS 2000 is not as simple as it is. You can open the file, then give up (unconsciously) control of additional threads. What happens if there is a thread trying to open the same file? Each thread cannot open the file, or open the file in a shared mode (this is not what is desired). Even if Wi N D O W S is not robbed, there may be another thread to perform other processes, causing the same problem. For many operating systems (such as u N i x), this is an old problem, and its solution is not complicated. Wi N D O W S provides synchronous objects (see Chapter 4), which helps solve such problems. You need to understand that this type of problem will eventually happen.

1.5.2 Unicode

By default, Windows 2000 does not use a N s i characters, and all internal strings are u n i c o d E. U N i C O D E is a 1 6-bit character sequence (not an 8 bit using A N S i). Under U N i C O D E can accommodate different symbols and non-English characters in additional space. Of course, most programmers (at least in the United States) still use A N S I. If you like, Wi N D O W S also allows A n s i (at least, most). Its skill is that each received or returned string A P i function is actually two functions: a mating U N i C O D E, another mating A n s I. When you set up a scheme, development tools (such as Visual C ) usually allow you to choose which function you use. It is assumed that the command M e s S A g e B O x is used in the C program. Its compiler defines the symbol based on whether to use U N I C O D E mode. The header file defines a macro to M e s S A g e B O X and expands its M e s S A g e b O X W compiled by M E S A g e B O X A and U N I C O D E compiled by A N S I. This will result in confusion when the error message and the debug output reference M e s A g e b o x a. To convert a string from A N S to u N i C O D e, Wi D e c H A R to M u L T I B Y T E and M U L T I B Y T E TO WI D E C H A R function can be used. Of course, the U N i c O d E string does not completely convert to a A n S i string, and Wi N D O W S may replace some characters that A n S i cannot be represented. 1.5.3 file system problem

Windows 2000 uses the installed file system technology. This means that on the same machine, may involve different file systems. You may use V Fat (Windows 95 compatible system) on a hard drive, while N T F S (Wi N D O W S) is used on another hard drive). Typically, as long as the names of the file are not set, these problems will not harass you. For example, the name of the setting file contains 1 to 8 characters, 1 period, and 1 to 3 characters, which will probably go wrong. If the name of the file is considered a mysterious, unknown string, there may be no problem. Before NT 4, the file system of the H P f S (O S / 2) can be installed. NT 4 withdrew the official support for H P F S, although the report on I N t e R N e t indicated, if desired, can be installed from the NT 3.15 mounting disc. It is worth noting that N t f s does not run on a soft disk. NT 3 means that there is no long file name on the soft disk. NT 4 and Wi N 2 0 0 0 Support V FAT (Windows 95 file system), which supports long file names, so you can use V FAT on your floppy disk. However, there is still no additional characteristics provided by N t f s. What is these features? N t f s is the basis of security. The security of the file cannot be protected on the FAT and V FAT disks. Why do you have FAT and V FAT? Because the soft disk is very important and cannot format a N t f s soft disk (this is not disclosed, if you want to do this, see W W W. N T S E C R e t s. C O m). Also, many users will install Windows 95, Windows NT, and Windows 2000 on the same machine. If there is no FAT and V FAT, the hard disk will not be shared between the two installations (still, not disclosed, W w w. N T s E C R e t s. C O m has a read-only N t f s driver for Windows 95). You have to run Wi N D O W s in N t f s, and all situations are the same. However, you can't expect it. Some users are using V fat or even using H P f S. There is no temporary local hard drive, don't expect to find what it will be found online. The key is to assume that your name is not much about the file name. 1.5.4 DLL

Dynamic Link Libraries, DLLs are architects of Wi N D O W S. Each time you call the system command, D l L is supplied with M i C R O S O f T. This allows you to use the code library, and actually do not include them in the link time. There are three advantages: make the program smaller, different programs can share the same library, and the library update does not need to be re-linked to the program. Of course, you can also create your own D L1 and use them. Windows 3.1 D L1 has many WIN2000 DLLs that cannot be shared. Different from Windows 3.1, Wi N 2 0 0 0 Call D L1 function to prompt when the process is loaded with D L and when D L is Use D L1 to allocate resources for each process. When more than one process uses a D L, D L1 can set a variable for each process, or share a common variable between the processes. This takes into account the raw form of shared memory, and if it is necessary to communicate between processes, it is quite useful. When Wi N D O W s is attempt to load D l L to the program process space, first detect whether to load the same D l L for other processes. If so, Wi N D O W S will simply attempt to map D L1 in the two processes (of course, remove private data memory). Only when the second process has free memory, and at the same address, the first process is only valid in the case of using D L1, so it is effective. What if the second process is using some of the memory required? At this time, Wi N D O W s must be reloaded D l L (unless the memory page) is shared. This means that two processes that use the same D L L may be inconsistent with the address of D L1. This is not a general problem. If you use D L1 in shared memory, there will be a problem. Last line: Do not point your pointer to shared memory. Conversely, consider using the offset from the shared memory header address. We will learn more about the topic in Chapter 6. 1.6 Development Tool

Wi N D o W s has no shortcomings in development tools. Of course, the materials of most developers of Wi N D O W s have the credit of C programmers, this book is no exception. Even if you don't plan to use C , almost all M i C R o S O f T documents are written with C (at least in front of other languages, it is also known as it is gradually familiar with it. However, there are of course many feasible Wi N D O W S development platforms. For example, J a v A is currently very popular. B O R L A ND has Delphi, visualized Pascal (and C Builder, which use C in the same way). Languages ​​that are often ignored are VI S u a lbasic (VB). V B shows a real compiler, powerful A c t i v e x support, can call A P i without power However, there are many other development tools, while C , J a v A and V B are of course the main development tools that may be used to develop Wi N d o w s at the underlying. The examples in this book are almost written in C , but the direct solution section in this chapter will show how to call A P i from these three languages. Conclusion This chapter shows some concepts of Wi N D O W S and the differences between other operating systems familiar with. When you want to build awareness benchmark, please, Wi N D O W s is different from the operating system you are familiar with, don't reject it. In the following chapters, you will read more of Wi N D O W S, including the development of the subject content in this chapter. After reading this book, you will naturally accept Wi N 2 0 0 0, let me not believe you! 1.7 Direct Solution

1.7.1 selection of development tools

When reading this book for details on Wi N D O W s, it will probably involve C more than other things. On the other hand, many programmers have turned to use J A V A, which is also desirable for most design projects. However, most examples in this book are C programs with class library (M f C), because most C programmers always use M f C. You should be able to read these examples (including program listings and appendices), despite some small difficulties. The graphical user interface is not important, where you can see many examples of the console application. The console application allows the user to write C or C code, each with M a I n function and standard I / O function. Another interest-to-language choice is Delphi (or associated C Builder) of B O R L A N D. This programming environment is highly graphically, and it is fully able to write a bottom code and call PASCAL (Delphi) or C (C Builder) language A P i. Although Visual Basi is very tone by the system programmer for a long time, VB6 is also a good choice. If you need to use A C T I v e x, select V B 6 is particularly correct because V B 6 has a lot of work in constituting A C T I v e x. V B 6 also provides code compilation of local machines, and eliminates many of the defects in previous V B version performance. You can easily call most A P I. Its main disadvantage is that the V B program requires a considerable runtime library. This is also the disadvantage of the M f C program, but this does not prevent people from using M f C. Regardless of the language choosing, it is necessary to understand the principles of the Wi N D O W S tag. That is the true purpose of the content discussed in this book, although most examples are described in the C language. 1.7.2 architecture of Windows

For application programmers, Wi N D O W s provides 2 G b flat virtual address space for each program (some versions are 3 G b). It usually uses the specified 3 2-bit pointer, it can address from 0 to 2 g B. Commands for the operating system are saved in the dynamic link library (D L1). These commands transmit your needs to the Wi N 3 2 subsystem, which controls the Wi N D O W S execute program that completes the actual work. By this point, the execution program further calls the machine predetermined portion of the processing operation in the hardware abstraction layer (H a L).

1.7.3 understanding process

It is important to confuse the Wi N D O W S process and other operating systems process concepts. In Wi N 2 0 0 0, a process is equivalent to a container. What is the container contains? Storage space, open files, resources, and threads. The thread is actually an execution unit, Wi N 2 0 0 0 Scheduled a thread progress, but does not arrange the progress progress. A process begins with a thread that can create more threads (and these threads can create more threads). The thread in a process shares all things in the process. They have uniqueness is the execution point in the program, and the location of local variables in the process address space. There is no resource that is not shared in different processes, unless the communication technology between the specified processes is used to share resources.

1.7.4 Adding a P i from C

From most C environments (including Visual C ), call A P i is quite simple. As long as you are confident that contains the appropriate header file (usually W i N D O W s. H) and the correct library (by online help, you can find the required library). So the call is achieved. A P i is designed to conform to the C / C environment. Since everything is already set, we can easily call A P i, so we don't need to consider so much. If you are using libraries like M f C, you need to include library header files such as W i N D O W s. H (or other file). To remember, according to the use of A N s or in use U N i C O D E, the compiler will change the name of many A P i in the background, and how they do corresponding changes. For example, M e s s a g e b o x command changes to M e s S a g e B O X a compiled A N S I and ME E S A G E B O X W for U N I C O D E. These names can be seen when viewing image files, debugging information, or compiler error messages. By the way, it is easy to call a P i from D e l P H i. As long as the correct unit is included, it can be linked with the corresponding library. Also, these are always set up. 1.7.5 Calling a P i from V B

Although V B usually does not call A P i, you can use some means to implement V B, called A P i. The trick is that V B can almost invoke any of D L1. Since the A P i of Wi N D O W S is a collection of D L1, V B can constitute a A P i command. Because A P i is large, each time you run any program, in order to understand each A P i command, it will reduce the programming speed of V B. However, most programs only use a minority command. M i C R O S O f T provides a P i text reader (API TEXT VI E W E R). Using this reader, you can select a command of interest, and the browser will report them as a description (D E C L A R e) to send to the selected file. These instructions report make it possible to call A P i. This is very convenient, but there are some problems. The reader does not understand the dependencies between them. Depending on the creation of the output file process, it may be wrong when trying to run the program. For example, in the following statement, an error is obtained: public const key_execute = (key_read) Check the file, it will find that k e y _ r e a d is defined behind the file. Therefore, you must manually define the definition of k e y _ r e a d, so that it is before k e y _ e x e c u t e. Another problem is very similar. Only for content based on what you need, you can output a function or identifier (as KE-y _ R e a d) in the above example. Once it is determined, it is possible to find additional items. This continues until the all-dependent relationship is excavated.

1.7.6 Calling A p i from Visual J

Calling A P i from Visual J is very challenging, because you have to use J A V E's native program interface, it is also very difficult. 12 WINDOWS 2000 System Programming

However, J / D I R E C T of M i C R O S O F T makes it easier. J / D I R E C T includes two parts. The first part allows you to invoke any of the functions in D L s without having trouble, the second part is to simplify the generic WIN32 API. Using the first part, use special annotations and procedures of J AVA code, can define ANSI M ESSAGE B OX functions: / ** @ D11.Import ("User 3 2") * / private static native int MessageBox W, String MSG, String Title, Int Flags; also can call Unicode versions, such as: / ** @ D11.import ("User 3 2", Unicode) * / Private Static Native Int MessageBox (int W, String MSG, String Title, Int Flags; of course, do not want to write these statements throughout the API, so M ICrosoft applies several classes to package the entire API. You may call M Essage B ox: com.ms.win32.user32.messagebox (0, "H i", "Java Message Box", 0); This is not trouble, u Ser 3 2 care Conversion of all data types and inputs of DLLs. 1.7.7 internet resources

Here, the U r L: W w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w. C O M-author's site, each month will have various M f C tips and information about this book. w w w. S Y S Y N t e R n a l s. C O m- is a URL looking for N t and Windows 2000 system applications. W w w. z D n e t. C O m / p C C O m p / f E A T U R E S / F E A 0 7 9 7 / N T / W E L C O m E. H T M L- From PC Computing Magazine, the topic is an interesting article "NT LIES".

(During the article finishing ...)

转载请注明原文地址:https://www.9cbs.com/read-3309.html

New Post(0)