API Programming Series #2

Problems when using API Text Viewer

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.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is anticipated with distaste, performed with reluctance, and bragged about forever.” - Dan Kaminsky