| | | | | ByVal dwShareMode As Long, _ ByVal lpSecurityAttributes As Long, _ ByVal dwCreationDisposition As Long, _ ByVal dwFlagsAndAttributes As Long, _ ByVal hTemplateFile As Long _ ) As Long | | | | | | The CreateFile function returns a low-level handle to the file. Of course, using CreateFile only makes sense when it offers some advantages over the other higher-level and much simpler choices. We will see an example of this in Chapter 10, Objects and Their Handles, where we will use the file handle to map a portion of the file directly into an application's virtual memory space. | | | | | | To create a simple text file, it makes more sense to use one of the simpler, higher-level methods. In fact, the FileSystemObject object uses the CreateFile API function to accomplish its goal, so why not take advantage of that? Indeed, Figure 1-1 shows the API functions that are imported (that is, used by) the file SCRRUN.DLL, which houses the FileSystemObject object. Note that the list includes CreateFileA and CreateFileW, which are the ANSI and Unicode versions of CreateFile. (Incidentally, the program rpiPEInfo shown in Figure 1-1 is one of the applications we will create in this book.) | | | | | | To be sure, the Win32 API is the lowest level accessible to the programmer (VB or VC++). It allows the VC++-programmer to access the full power of the Windows operating system, and it allows the VB programmer to get much closer to this goal than by using VB alone. | | | | | | When faced with a programming issue, however, it is generally wise to find the highest-level solution, except perhaps in cases where performance is a serious issue. As you will see as you read this book, there are a great many situations in which the Win32 API is that highest level! | | | | | | Working with the Win32 API is not like working with Visual Basic. With the Win32 API, we are much "closer" to the operating system, and there are far fewer protections than under Visual Basic. Indeed, VB is a very protected environment, for which we pay a penalty in terms of limited access to the operating system itself and very limited direct access to memory. | | | | | | In particular, when we read or write to memory, we take certain risks (but nothing that a reboot won't fix). If we attempt (either deliberately or inadvertently) to write to or read from protected memory, the operating system will hopefully raise a General Protection Fault, or GPF. Figure 1-2 shows an example of a GPF dialog (under Windows NT 4.0). | | | | |