Visual Basic
  Home arrow Visual Basic arrow Page 4 - Accessing the Windows API in Visual Basic
Web Buyers Guide
Iron Speed
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC

Accessing the Windows API in Visual Basic
By: Jason Brimblecombe
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 76
    2001-12-12

    Table of Contents:
  • Accessing the Windows API in Visual Basic
  • What is the Windows API?
  • Exploring the API function list
  • Your first API call
  • Calling the API
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Application developers can seamlessly integrate the Advantage Database install with their application install. Learn the best practices used when setting up silent installs with this seminar.

    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...

    More Visual Basic Articles
    More By Jason Brimblecombe


       · Excellent, very helpful content - it is a pity it has such a cluttered display.
     

    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






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway