Home arrow Visual Basic arrow Page 4 - Accessing the Windows API in Visual Basic
VISUAL BASIC

Accessing the Windows API in Visual Basic


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.

Author Info:
By: Jason Brimblecombe
Rating: 4 stars4 stars4 stars4 stars4 stars / 127
December 12, 2001
TABLE OF CONTENTS:
  1. · Accessing the Windows API in Visual Basic
  2. · What is the Windows API?
  3. · Exploring the API function list
  4. · Your first API call
  5. · Calling the API
  6. · Conclusion

print this article
SEARCH DEVARTICLES

Accessing the Windows API in Visual Basic - Your first API call
(Page 4 of 6 )

Browsing through the list of available items in the API viewer, you can probably guess what most of the functions do, like the 'AddPrinter' function, for example. But what the heck is 'FlushConsoleInputBuffer'? It doesn't matter if you don't understand every single API call, but if you want to know what each one does, you can visit the Microsoft API resource page, located at http://www.microsoft.com/api/.

So, let's get started with writing our very first program that takes advantage of the Windows API. Start by creating a new project in Visual Basic 6. You will require a single form and one module (you can name them whatever you want, because it doesn't really matter in our example). The program that we are going to write will simply display a message box, which contains the path of the Windows directory.

Using the API Viewer, look for the function called 'GetWindowsDirectory'. When you've found it in the list, click the 'Add' button. Its source code should appear in the selected items box. Copy the source onto the Windows clipboard. In case you are unsure, here's what the source should look like:

Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

We now have access to the source code that will call up the API function. As you can see, this API is located within the Kernal32.DLL file. With the source code copied to the Windows clipboard, return to Visual Basic and paste it in as part of the source code for the Module. It should be pasted at the top, before anything else. When your program is interpreted and executed, your application will now make a request directly to an API call. Our single API decleration is useless at the moment, however. We need to call the API function from within our program. That's what we will do right now...
blog comments powered by Disqus
VISUAL BASIC ARTICLES

- Developing an XML Web Service Using Visual S...
- Creating an HTML File List with VB
- Fun with Email: VB6, CDO, MAPI, and a Remote...
- Extranet/Intranet Dictionary Cracker in VB
- Finding Default App Icons With Visual Basic
- Registry Fever With Visual Basic
- Implementing An ADO Data Control With VB6
- Printing With Visual Basic
- MSMQ Part 1/2: Architecture and Simple Imple...
- Magnifying The Desktop With Visual Basic
- Sending Email With MAPI Components in Visual...
- Two Person Chat With The Winsock Control And...
- A Real-Time ActiveX News Control
- Accessing the Windows API in Visual Basic

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials