Preface

Page xiii
PREFACE
This book is intended for the intermediate- or higher-level Visual Basic programmer. The book has two goals:
Describe the Win32 API and how to program it from Visual Basic versions 5.0 and 6.0.
Describe the basic operation of the Windows NT and Windows 9x operating systems.
As you may know, the Win32 Application Programming Interface, or Win32 API for short, is the programming interface that is used to programmatically control the Windows operating system. More specifically, the Win32 API consists of a collection of functions and subroutines, supplied in a handful of dynamic link libraries (DLLs), that provide programmatic access to the features of the operating system.
The first goal mentioned earlier is a practical one since, as we will see, the Win32 API can be of immense use in extending the power of Visual Basic. The second goal is less practical, but is equally important, since Microsoft's documentation seldom takes into account what the reader knows or does not know. Hence, a grounding in the basics of the Windows operating systems will help VB programmers understand Microsoft's documentation.
Of course, the two goals are not unrelated. Indeed, the purpose of the Win32 API is to implement the services (or features, if you will) of the Windows operating system. Hence, in order to understand the function of the Win32 API, it is important to have some understanding of how Windows itself works.
I should also point out that this book is not intended to be an encyclopedia for the Win32 API. My goal is to present you with enough information to get an overall feel for the Windows operating system and the Win32 API and to allow you to

Page xiv
further your education by using Microsoft's documentation, which is seldom as pedagogical as it should be!
Prerequisites
The prerequisites for this book are simple: an intermediate-level (or higher) knowledge of Visual Basic version 4 or later and a desire to stretch VB into the realm of Windows system programming. You may want to do this for a specific purpose perhaps you are writing a specific application that requires more than VB can handle or just to learn more about how Windows works without suffering through the very steep learning curve associated with Visual C++-style Windows programming.
You do not need a background in VC++ (or C++ or C) to read this book, nor do you need to have any previous experience with the Win32 API.
What's on the CD-ROM?
The CD-ROM that accompanies this book contains several applications that we discuss in the book. You may want to use these applications and/or modify them to suit your particular needs. Please note that these applications were written as learning tools, not as commercial-grade applications. For instance, they have very little error-handling code and their interfaces are a bit rough in spots. (For example, I paid little attention to issues related to various screen resolutions.)
Note also that the code is for your use only it is not for redistribution. (Incidentally, the prefix rpi found on most of these application names stands for Roman Press Inc., which is the name of my computer consulting/publishing company.) If you find any serious problems with an application, or a particularly interesting use or modification, I would appreciate hearing about it by email or via my web site at www.romanpress.com.
rpiAPI.bas and rpiExampleCode.bas
The included standard VB 6 code module rpiAPI.bas contains the declarations and most of the important utility code used by examples in the book. The more expendable code is contained in the rpiExampleCode.bas module. The point is that you may want to use the code in rpiAPI.bas in your own projects, but the code in rpiExampleCode.bas has more of a one-time-use nature.

Page xv
Applications
Here are the examples discussed in the book and included on the CD-ROM:
rpiAllocMemory
An example that is used to demonstrate the rpiAccessProcess.dll, which can access a foreign process for memory allocation, data transfer, and more.
rpiBitBlt
A demonstration of the BitBlt function.
rpiClipViewer
A Clipboard viewer application.
rpiEnumProcsNT and rpiEnumProces95
Display the current processes on a system.
rpiEnumWins
Shows information about all windows currently in a system.
rpiFileMapping
Demonstrates memory-mapped files.
rpiGlobalHook
A global mouse hook example. Uses rpiGlobalHook.DLL.
rpiLocalHook
A local mouse hook example.
rpiPEInfo
Retrieves information about an executable file.
rpiSpyWin
Retrieves information about a window.
rpiSubClass
Demonstrates subclassing.
rpiThreadSync
Demonstrates thread synchronization (mutexes, events, and semaphores).
rpiDLL
A DLL with some miscellaneous functions, including rpiVarPtr, which does the same thing as VB's undocumented VarPtr function on nonstring variables and can be used to simulate StrPtr. Also included are the functions rpiGetTargetByte, rpiGetTargetInteger, rpiGetTargetLong, and rpiGetTarget64, which perform address indirection in VB.
rpiUsageCount.dll
A DLL that can be used to tell when a VB application is already running.

Page xvi
The rpiAPIData Application
The CD also contains an application called rpiAPIData, which is essentially just a front end for a database that contains tables of the following:
More than 6,000 Win32 constants and their values
More than 1,500 VB-style API function declarations
Approximately 1,000 message identifiers
About 200 style constants
More than 400 structure (type) declarations
More than 600 Win32 data type declarations
Figure P-1 and Figure P-2 show the main windows for this application. The application can be used to extract function, constant, type, and other declarations for use in VB projects. You might even want to turn the application into a VB add-in, something I find extremely useful. (If you need information on creating VB add-ins. let me suggest my book Developing Visual Basic Add-ins, also published by O'Reilly.)
0xvi-01.gif
Figure P-1.
rpiAPIData

Page xvii
0xvii-01.gif
Figure P-2.
rpiAPIData: data type view
Resources and References
Win32-related programming, whether in VC++ or VB, is definitely complicated. To do an effective job, you will need good reference material. Aside from this book, I recommend the following:
As you may know, starting with version 6, Microsoft has moved the entire documentation for Visual Studio (VB6, VC6, VJ6, etc.) to its MSDN Library, a copy of which comes with VB6. Thus, you get documentation not only for VB6, but also for VC6 and the Win32 API. This is without a doubt the most useful documentation for Win32 API programming in VB. In fact, it is about the only documentation that I use. (The version of the MSDN Library that is included with Visual Studio is referred to as a Visual Studio Edition of MSDN. Frankly, I have not been able to determine how this differs, if at all, from the subscriptid] in this book, it refers to the MSDN Library documentation.
To get quarterly updates, you can subscribe to MSDN for about $100 per year (check it out at http://msdn.microsoft.com/). This may be worth doing, since

Page xviii
the library also contains some very useful articles, along with the Microsoft Knowledge Base, which is constantly being updated.
If you want to learn more about the Windows operating system, I can recommend Jeffrey Richter's book Advanced Windows, Third Edition, from Microsoft Press. Note, however, that there is no VB code in this book it is strictly VC++ and it is fairly heavy going. If you want to learn more about the internal workings of Windows NT (which is the Microsoft operating system in everyone's future), I recommend Inside Windows NT (Second Edition) by David Solomon, also from Microsoft Press. Note, however, that this book is quite technical and contains no code at all.
Conventions in This Book
Throughout this book, I've used the following typographic conventions:
Constant width
Used for code blocks and examples, commands, constants, data type names in C, keywords, methods, objects, statements, structures, syntax prototypes, and values.
Constant width italic
Used for parameters and variables. Variables are italicized only in body text, not in code blocks.
Italic
Used for filenames, functions, procedures, classes, and URLs. Also used for emphasis and to introduce new terms.
How to Contact Us
We have tested and verified all the information in this book to the best of our ability, but you may find that features have changed (or even that we have made mistakes). Please let us know about any errors you find, as well as your suggestions for future editions, by writing to:
O'Reilly & Associates, Inc.
101 Morris Street
Sebastopol, CA 95472
1-800-998-9938 (in the U.S. or Canada)
1-707-829-0515 (international/local)
1-707-829-0104 (FAX)
You can also send messages electronically. To be put on our mailing list or to request a catalog, send email to:
nuts@oreilly.com

Page xix
To ask technical questions or comment on the book, send email to:
bookquestions@oreilly.com
We have a web site for the book, where we'll list examples, errata, and any plans for future editions. You can access this page at:
http://www.oreilly.com/catalog/win32api/
For more information about this book and others, see the O'Reilly web site:
http://www.oreilly.com
For technical information on Visual Basic programming, to participate in VB discussion forums, or to acquaint yourself with O'Reilly's line of Visual Basic books, you can access the O'Reilly Visual Basic web site at:
http://vb.oreilly.com
You can also consult the author's web site at:
http://www.romanpress.com
for information on his books and software, as well as articles on VB/VBA programming and related topics.
Acknowledgments
I would like to thank Ron Petrusha, my editor at O'Reilly, and Tara McGoldrick, from the editorial staff, for their help with this challenging book. My special thanks to Matt Childs for doing a careful technical review of this book not a simple task, to be sure.
Also thanks to the production staff at O'Reilly & Associates, including Jeffrey Liggett, the production editor; Edie Freedman for designing another memorable cover; Mike Sierra for tools support; Rhon Porter for illustrations; David Futato, Jeff Holcomb, and Claire Cloutier LeBlanc for quality control; and Ellen Troutman Zaig for the index.



WIN32 API Programming with Visual Basic
Win32 API Programming with Visual Basic
ISBN: 1565926315
EAN: 2147483647
Year: 1999
Pages: 31
Authors: Steven Roman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net