The Application Programming Interface

Team-Fly    

 
eMbedded Visual Basic: Windows CE and Pocket PC Mobile Applications
By Chris Tacke, Timothy Bassett
Table of Contents
Chapter 9.  Harnessing the Windows CE API


Most of the functionality of any Windows operating system lies in dynamic link libraries (DLLs). It's also true that most of those DLLs aren't COM compliant and therefore can't be added to your eVB project as a reference or component. You can, however make calls to functions within almost all the DLLs available if you know the function's method signaturethat is, the function's name as well as all its parameters and parameter types.

These functions are exposed in APIs and, as I said, most DLLs have one. The challenge is determining what functions are exposed through the API and what the method signatures look like. Making incorrect API calls is a good way to cause application or even system failures, potentially causing the user a data loss; therefore care should always be taken when declaring and calling API functions.

Using API functions requires that you follow three rules:

  • All API declarations must be in a module (.bas file) and must occur in the General Declarations section before any application functions are declared.

  • All API declarations must follow correct declaration syntax.

  • You must distribute pvbdecl.dll with your application.

The first rule is simple and straightforward. API declarations aren't valid in form code pages. They must be made in modules, and they must be at the top.

The second rule of using an API function is that the declaration must follow a specific syntax, which can be generally written like this:

 [Scope] Declare FunctionSub  {   FunctionName}  Lib "  {   Library File Name}  " _        [Alias "Library Function Name"] _        (  {   Function Parameter List}  ) As  {   Function Return}  

First, you can optionally declare a scope for the function. If you don't explicitly declare scope, it will be assumed to be Public.

Next, use the keywords Declare Function (or Declare Sub if the API has no return value), followed by the name used in the eVB code to call the function. Most often this is either the exact name of the function in the library file or something very close, as you'll soon see.

After the function name, you must tell the compiler where to find the functionthat is, in what library (DLL) file. This is accomplished with Lib and the filename, without the extension.

Next, you can optionally have an alias for the function. This is where you must put the exact function name if you didn't use it previously. The reasoning behind this is that many APIs in Windows have two versions, one for ANSI, usually suffixed with an A, and one for Unicode, usually suffixed with a W. Because it would be uncommon to need both versions in a program, the functions are usually aliased to remove the suffix.

Finally, provide the function's parameter list and return values.

A full API declaration, then, would look something like this:

 Public Declare Function CharLower Lib "Coredll" Alias "CharLowerW" _        (ByVal lpsz As String) As String 

Team-Fly    
Top
 


eMbedded Visual BasicR. WindowsR CE and Pocket PC Mobile Applications
eMbedded Visual BasicR. WindowsR CE and Pocket PC Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2001
Pages: 108

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net