Win32 has a ReadFile and a WriteFile, but these functions are normally worthless for Visual Basic programmers because the Basic Input and Print statements handle the same tasks in a friendlier manner. But Win32 also provides functions that Basic doesn’t provide.
It’s a common belief that you can speed up your Visual Basic I/O by using API calls such as ReadFile and WriteFile rather than Basic features such as binary I/O with Get and Put. I don’t be-lieve it. Any slight advantage you might get from the API will be washed out by the cost of disk access. Do you doubt it? Prove me wrong. I won’t argue with facts. If anybody can show me code demonstrating that API calls are significantly faster than Basic I/O for comparable operations, I’ll publicly grovel in abject humiliation. I’ve posted this challenge in several online forums, but so
far nobody has made me bow. There are reasons to use API I/O calls (compatibility with other API calls), but I maintain that speed isn’t one of them.
Unfortunately, some of the most useful API functions aren’t Basic-friendly. They return pointers to string positions that do you no good in Visual Basic because of Unicode conversion problems. Others return usable data, but in a style unbefitting what Visual Basic programmers are accustomed to. The previous edition of this book provided a C DLL to supply a few key functions that Visual Basic allegedly couldn’t handle. But we don’t need no stinkin’ DLL for this edition. If it’s worth doing, it’s worth doing in Basic.
Under Visual Basic version 3, many programmers discovered
a secret tool for getting the free space on a disk. The following
Declare statement gave you a function that returned the free bytes on the current drive:
Declare Function DiskSpaceFree _
Lib “SETUPKIT.DLL” () As Long