Image of Navigational Map linked to Home / Contents / Search The Collections Classes Discontinued

by Jim Karabatsos - GUI Computing
Image of Line Break

In the previous edition of AVDF, I launched into what was to be a series of articles describing a set of collection classes for use in VB, starting with that issue's coverage of a Vector class.

Well, it turns out someone has already done that. Bruce McKinney has written a terrific book called Hardcore Visual Basic (second edition) and in it he covers a whole set of collection classes. This book is a must-have for serious VB developers. Bruce's style is very engaging, making it a very easy read; on first browsing through the book it is easy to miss just how much good information is in it. Bruce obviously knows his stuff and he has carefully avoided writing yet another book on how to make a Beep in VB.

I would thoroughly recommend this book to all serious VB developers. You can get a look at it through MSDN, but you will want to buy a copy for a reason I will get to in a moment. If you are interested in pursuing the concept of a set of collection classes, I would refer you to that book.

I became aware of this book through a funny-after-the-fact series of events that I will share with you so you will understand why I have chosen not to continue with this series of articles. It turns out that the Bruce visited the GUI web site and read the Vector class article and was, err, surprised at just how similar it was to his implementation. He e-mailed us here at GUI and we compared his code to my code. I have to admit that, if it weren't for the fact that I had written the code myself, I would have jumped to the same conclusion that Bruce did, namely that the code we published had been "borrowed" from his work.

What made the matter even worse were the similarities between the issues that I raised in the text of the article and those in his book, even to the point of both of us complaining bitterly about the dialog box from hell and raising much the same points.

Bruce had even come up with substantially the same hack of patching the VTable to allow custom collection classes to participate in the For/Each processing that I alluded to in that article.

All in all, I can see why he was concerned. It was only after a series of e-mail messages that we were able to convince Bruce that this was genuine coincidence, or at least to admit that this was a possibility. I suspect that Bruce continues to be suspicious, and I can't say I blame him; as I said above, if it wasn't for the fact that I wrote the code myself, I would have been suspicious too. However, gentleman that he is, Bruce has kindly agreed to let the matter rest, with no conditions or limitations of any sort.

Having (now) read the book, I decided to abandon that series of articles. The bottom line is that the code Bruce has presented in his book is pretty close to what I would have written (although probably not as close as the Vector code <g>) and the narrative covers most if not all of what I would have discussed. So rather than tempt fate, I refer you to that book and move on to other matters.

Now, why would you want to buy a copy of Bruce's book, given that it is on MSDN? Well, apart from the fact that I like a physical book better because I can read it anywhere, it turns out there is a real gem hidden in the book that you simply MUST have. Bruce has created a type library that defines all of the important functions, constants and types exposed by the Win32 API.

If you have worked with ActiveX (née OLE) at all, you will undoubtedly be aware that a type library is a way for an interface to be defined, so that development tools (for example) can determine the properties and methods exposed by a component. When you add an object to the Project references list, you are actually telling VB to read the information stored in the type library so that you can use those objects in your code (and more particularly to early bind to them).

A type library can be included inside a DLL or EXE file or it can be stored in a stand-alone file, in which case it generally has an extension of TLB (or more rarely OLB).

What most people do not realise about type libraries is that they can be used to describe the functions in ordinary (ie non-ActiveX) DLLs too. In both VB4 and VB5, a document was quietly shipped on the CD-Rom describing how you could use a type library to do this, but most developers never even saw it. Even those who did mainly saw the information on parameter-passing necessary for interfacing between VB and regular DLLs. It was from this document that I first figured out how to return a string return value from a DLL function, for example, and I don't want to even guess at how many times I've been asked that question.

On several occasions, I had considered what would be involved in writing a program to parse the various windows header files used in C development and create a type library for the Windows API (really, I had, Bruce <g>) but I never had the time to do this. Such a translation would have been better than nothing but there are many places where the type library would need to be tweaked to make it more useable from VB.

Well, it turns out Bruce has gone one better. He has created such a type library and spent a LOT of time hand tuning it for VB. All (or at least most) of the important API functions, structures and constants are defined and this is done in such a way that they are useable from VB.

All you need to do it reference the type library in your project and then you can freely use these API elements in your code. There is no need for all those Declare and Const statements and more importantly for figuring out which ones you have used and where. With this approach, the entire API is immediately available and you pay no penalty for defining functions, types or constants that you don't actually use.

Bruce has two versions of the type library, one for the Ansi functions and one for the Widechar (Unicode) functions. You would generally use the Ansi version so that your program would run under both Win95 and NT. If you know that your program only ever needs to run under NT, then using the Widechar version would be more efficient as this would avoid the constant conversion between Ansi and Unicode..

Folks, you NEED this tool, and it comes free with Bruce's book. If I were Bruce, I'd sell the type library as a development tool and just call the book the manual. Check it out. ISBN 1-57231-422-2 on Microsoft Press. Available from GUI for $A99.95.



Written by: Jim Karabatsos
January '98

Image of Arrow linked to Previous Article Image of Arrow linked to Next Article
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]