However, you need to watch out for these common glitches:
If you copy the declarations right from the API Viewer, then remember to set the scope of the function appropriately. This can be done by setting the appropriate radiobutton. The scope is Public
by default, the function has public scope. But VB does not allow public Declare statements within form modules. So if we are copying the Declare statements into a form module, they should be explicitly specified as Private
, by clicking the appropriate radio button.
But this makes the declarations invisible outside the module in which they are defined. So the functions should be declared in every module that needs to use them, which can be pretty cumbersome in a large project. Declaring them in a separate .BAS module where they can be declared as Public and are therefore accessible to all the modules eliminates this duplication. This also permits easier maintenance.
Another common error is the Ambiguous Name detected error. Put simply this means that the module contains more than one function or constant having the same name, causing the ambiguity. Since most of the functions are Aliased, they are referred to by different names. In such cases we can change the function name at the declaration and invocation points and the code will work fine. (We will discuss aliasing in more detail, later on in this article)
There is one more error that you need to keep a really sharp eye out for, mainly because it comes from an unexpected source. The Win32api.txt file supplied by Microsoft contains some errors, which can cause you endless hours of frustration. Since we copy it from the API Viewer, the Declaration would be the last place we'd expect an error to arise especially as the file itself is a Microsoft product.
But sadly this file contains a number of errors that are particularly hard to track down. There's nothing much you can do about it, except of course to correct any that come to your attention and consult a good API guide or SDK documentation when things don't seem to go as expected.
The API-Guide created by the KPDTeam seems to be a very good replacement for the MS API viewer. It contains good explanations, examples and is structured in tree hierarchy that enables better comprehension.
It also comes with a good viewer which can be accessed as an Addin from within VB and is my choice whenever I do aPI programming.
API Programming Series #2
- Foreword
- Declaring API functions
- Problems when using API Text Viewer
- Here it comes...
- The Code
- Aliasing
- Arguments
- ByVal and ByRef
Problems when using API Text Viewer
You might also like...
VB 6 books
-
Programming with Microsoft Visual Basic 2008
Programming with Microsoft Visual Basic 2008, Fourth Edition by the best-selling author, Diane Zak, is designed for a first course in programming. Using the most recent version of the software, Visual Basic 2008, this book teaches individuals how to ...
VB 6 forum discussion
-
CorelDRAW VBA: cdrTraceLineDrawing FAILS, producing single linear path instead of Centerline trace?
by dancemanj (0 replies)
-
client/server application using activex
by beautifulheart (0 replies)
-
System Error &H8007007E. The specifed module could not be found.
by swiftsafe (5 replies)
-
Invitation to take part in an academic research study
by researchlab (0 replies)
-
Send SMS with SMPP
by mmahmoud (0 replies)
VB 6 podcasts
-
Stack Overflow Podcast: Podcast #45 – Keeping it Sharp
Published 7 years ago, running time 0h54m
Our guest this week is Eric Lippert – language architect extraordinaire and famous for all his work at Microsoft in developing their languages Eric joined Microsoft right out of college and was originally working on VB It’s time for everyone’s favorite game: Name the Worst Feature of that Microso.
Comments