Sounds too good to be true, doesn’t it? Well, this time it’s not. You can use the Windows API type library to replace all your Windows Declare, Const, and Type statements. Load WIN.TLB (or its Unicode cousin WINU.TLB) in the References dialog box. Suddenly the whole Windows API becomes just another part of Visual Basic. You can examine the types, constants, and procedures in the Object Browser, and use the ones you need in your program without any extra work or resource cost.
The version of the Windows API type library provided with the first edition of this book was much less powerful and comprehensive than the one provided here. Visual Basic version 4 had significant limitations in its ability to use type libraries. With that version, you could get rid of most of your Declare statements, but not all by a long shot. Now you can. Almost. There’s still one obscure situation that requires Declare statements, and I’ll discuss it in “System Specific API Functions” in Chapter 6. There are also a few differences in the way you use type library functions and Declare functions, but they’re minor and I’ll deal with them as they come up in the rest of the chapter.
Just because you don’t need to write Declare statements for the API functions in my type library doesn’t mean you can’t or that you would never need to. My type library contains most of what you need, but if you run into a function that isn’t in the type library, it might be easier to write a few Declare statements than to modify the type library or create your own. Besides, Declare statements are a good teaching tool. If you understand how to declare a function, you’ll certainly have no trouble calling it. Therefore, this chapter takes a “back-to-basics” approach. It explains how Declare statements work even though you probably won’t need them very often.
Before I start talking about specific API functions, we need to take a brief look at what type libraries are.