December 22, 2014
Hot Topics:

Windows API Tutorial - Part Two

  • November 19, 2002
  • By Karl Moore
  • Send Email »
  • More Articles »

Unfortunately in the aromatic garden of API calls, not everything smells of roses. You get the occasional pile of manure, dumped by some ignorant sheep farmer.

And in this section, we're going to briefly cover a couple of the big stinks you may encounter plus give a little advice on how to avoid them.

API Viewer

First up on our naughty-naughty list, we have the API Viewer. Sure, it's been nicer than pie with us so far. But that's because we're just starting out. Once it gets to know you, it's start lying. Yep, lying.

For example, one of the best-known instances of the API Viewer telling a little fib is with the GetPrivateProfileString function, which allows developers to peek inside INI files and return values.

Unfortunately, earlier versions of the API Viewer declared this call incorrectly, causing much 'developer distress', a recognised medical condition. Thankfully this problem has been (debatably) fixed in the VB6 API Viewer, though a few lesser-used declarations are still flawed.

So if you're sure that code is correct but the API still insists on being horribly disobedient be sure to check out either the VB API reference site (www.vbapi.com/ref/) or Microsoft's API documentation (www.microsoft.com/api/) for assistance.

Passing Arrays

If you've not worked with arrays before, ignore this. Even if you have, you'll probably never need to pass one to an API call. But just in case, a warning - don't pass WholeArrays() direct to API calls. Instead, pass the first element of an array, RatherLikeThis(1). If you wanted the function to start work on the third element of the array onwards, you could pass it SomethingLikeThis(3). Either way, pass elements of an array rather than whole arrays. In addition, when doing this you usually have to pass the size of the arrays along with the API call.

No Currency

You can't pass the Currency data type to an API call. It's a VB-only thang. Instead, convert it to a Long or Double first.

There are a few other issues you may notice cropping up here and there, too. Buzzwords include memory alignment, the LenB function, subclassing and AddressOf function pointers, but that jargon is just beyond the scope of this API tutorial.

But if you're eager to learn more about all that jazz, read on...





Page 7 of 9



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel