Codingdomain.com

Accessing the Windows API with Visual Basic

Introduction

The 'Application Programming Interface', or API in short, is a very important part of operating software, like Microsoft Windows for instance. Those functions give the programmer access to the core functions, facilities and features of the operating system.

Programmers writing their Windows application in C, use the API functions naturally in their code. Since the Visual Basic 6 environment is somewhat limited, some Visual Basic programmers tend to use API functions to overcome these problems. This also confronts Visual Basic programmers with some new aspects of programming only known to C/C++ programmers.

The API functions are stored in DLL files, like gdi32.dll, kernel32.dll, user32.dll. There are many more libraries, but the ones listed above are the most important. All lot of API functions for are documented in the MSDN library (the Microsoft Developer Network library).

Using the API functions allows you to extend the capabilities of your software, but it's power must be handled with care. Almost needless to say, the Microsoft .Net environment might make these pages obsolete one day.

Just to let you know...
When you call any DLLs directly from Visual Basic, you lose the built-in safety features of the Visual Basic environment. This means that you increase the risk of system failure while testing or debugging your code. To minimize the risk, you need to pay close attention to how you declare DLL procedures, pass arguments, and specify types. In all cases, save your work frequently. Calling DLLs offers you exceptional power, but it can be less forgiving than other kinds of programming tasks.

Articles

A simple API call
A simple API call example.
Using data structures with API's
A small example of how to use data structures with API functions.
Using strings with API's
A small example of how to use strings with API functions.
Using variable argument types with API's
A small example of how to variable argument types with API functions.
Using callbacks with API's
A small example of how to supply a function callback argument to API functions.

Other resources

Data type conversions
A summary of the different data types used in Visual Basic and Windows API functions.
Visual Basic example applications for download
A set of Visual Basic applications demonstrating Windows API features. The source code is included with each example.
Windows DLL files for richer Visual Basic applications
A set of DLL files giving your Visual Basic application much more power. These DLLs use the Windows API for better toolbars, menu's and graphics support.

External Links

blog comments powered by Disqus