Windows API on visual Basic

Diposting oleh Admin | Saturday, July 19, 2008 | | 0 komentar »

The Windows Application Programming Interface, or API, is a complex set of functions for interacting with Windows. In this article, Jason attempts to shed some light on this topic by explaining what an API is, and providing an example of how to access one through Visual Basic.The Windows Application Programming Interface, or API, is a complex set of functions which allow Visual Basic, C++, Java and Delphi programmers to gain access to many of the functions that windows uses internally, such as printing, thread-based resources, and the registry.

In this article, I will try to help demistify this difficult topic by explaining a bit about API's. I will also provide a working example in Visual Basic to show how to call an API. You have probably heard of the Windows API numerous times, but you may not know exactly what it is. Basically, it is a whole set of implementation specific DLL hosted functions, which are accessible through Visual Basic, C++, Java and Delphi. The main API functions reside in three system DLL files, which are located on every computer that is using the Windows operating system.

  1. User32.dll - Handles the user interface
  2. Kernel32.dll - Working with files and your computers memory
  3. Gdi32.dll - Graphical commands
There are many more DLLs which are accessible through the Windows Operating System, however, they are seperated into numerous other system DLL files, which we will not discuss here.

Microsoft bundled all of the API functions into system DLL's so that they were easily accessible for developers from a number of programming languages. One advantage of using the Windows API is that each function is highly optimised, and usually written in C/C++, meaning that they are a lot faster than using the standard set of functions available in Visual Basic.

It is possible to use functions from other DLL files, as long as you know the declarations to access the functions. The developer of the DLL must provide a detailed set of documentation, telling other developers how to create an API decleration for the functions contained within that DLL.

API calls can be used to perform almost any Windows task, from shutting down a computer to installing a printer. Because of the multi-threaded mature of the Windows operating system, several programs can access the Windows API simultaneously.

Later in this tutorial, I will describe how to use one of the most common Windows API calls in Visual Basic.

Windows API functions are very fast and powerful, but actually calling them up and executing them can be time consuming. I would recommend that you only use Windows API functions if the task you are trying to implement is not available as a regular Visual Basic function or statement. Of course, the task that you want to implement may not be available as a Windows API function.

0 komentar