ATTENTION READERS! Lucky's VB Gaming Site is no longer active. For updated game programming information and tutorials, please visit The Game Programming Wiki!
The Windows API
Literally, API means "Application Programming Interface." Not too
descriptive by any stretch. The Windows API is actually a collection
of pre-existing functions inherent in windows that you can call upon
to do jobs for you within the windows environment. These functions are
stored within the multitude of DLL's that come with our most beloved
operating system.
To access these exotic functions, we first have to declare them in our
code. The syntax, however, looks a little ugly. Here's an example:
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Lets have a look at this. First, we see that this is a declare statement,
this may be unfamiliar to some of you. The windows help files state that
a declare is "used at module level to declare references to external
procedures in a dynamic-link library (DLL)." That's exactly what we're
doing here, we're referencing a procedure (actually a function in this
case) inside the DLL called "winmm.dll". This is the windows multimedia
DLL, and within it resides a function called "sndPlaySound" which allows
us to play wave files.
The word "Lib" indicates that "a DLL or code resource contains the
procedure being declared" and the word "Alias" indicates that "the
procedure being called has another name in the DLL." The rest of the
declare statement is simply the arguments passed to the procedure.
NOTE: If you intend to declare an API call from within an object
(such as a form) you must include the prefix "Private" before the
statement.
Ok, so now we have the function declared, and we're ready to use it in
code. We now treat it the same as we would any procedure we created
ourselves. For a specific example on how to use an API call from within
code, see the tutorial on Playing Wave Files.
Where did this magic little piece of code come from? It can be found
within the "Winapi" directory of your VB root. Within the "Win32api.txt" file
you'll see an incomprehensible list of procedures and constants that
make up the API. If you already know what you're looking for, then this
file may be useful to you, but generally it's best to read a book about
the API or look at web sites in order to find the useful portions.
API calls handling things such as wave output, bitmap display,
timing loops and more are explained in the other tutorials available
here.