Visual Basic
  Home arrow Visual Basic arrow Page 5 - Accessing the Windows API in Visual Basic
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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 / 101
    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
     
     
    ADVERTISEMENT


    Accessing the Windows API in Visual Basic - Calling the API


    (Page 5 of 6 )

    Place a command Button on your form and set the caption to 'Show Windows Directory'. I am going to assume that the name of this command button has been left as Command1. We will be attaching code to the Click event of this button, so open up the Command1_Click() sub-routine and enter the code below:

    Private Sub Command1_Click()

    Dim TheResult

    Dim TheWindowsDirectory As String

    TheWindowsDirectory = Space(144)

    'Fill 144 spaces in TheWindowsDirectory string

    TheResult = GetWindowsDirectory(TheWindowsDirectory, 144)

    'Get path and place it in TheResult string

    If TheResult = 0 Then

    MsgBox "Cannot get the Windows Directory"

    Else

    'Prepare the String for preview, and then display in a Message Box

    TheWindowsDirectory = Trim(TheWindowsDirectory)

    MsgBox "The Windows Path: " & TheWindowsDirectory

    End If

    End Sub


    Run the program and click on the command button. A messagebox similar to the one shown below should be displayed:

    The text of the message box is the windows director

    This message box shows that Windows has been installed into the directory (or folder) with the path 'C:\Windows\'. Your box may vary to mine, depending on where Windows has been installed on your computer.

    You may be asking yourself why an API function like this would be used. Well, if your project was built to perform a task that has a use for the Windows directory, then you are going to need to know the location of it, and using the API is the easiest way.

    If you hard coded the windows directory into your application. then an error may occur, because not all people choose to install Windows to the default c:\windows directory.

    There are other API functions available through the same DLL that perform a similar task to the one that we have just coded. For example, 'GetSystemDirectory' will display the full path to the Windows System Directory. In my case, the result would be 'C:\Windows\System', but it may say something different on other systems, depending on where Windows is installed.

    More Visual Basic Articles
    More By Jason Brimblecombe


       · Excellent, very helpful content - it is a pity it has such a cluttered display.
       · It is very helpful....It would be great if you can provide us the more examples on...
       · Excellent helps me a lot thank you very much and more power.
       · It is excellent the best that I have seen and that's it, I don't see the...
     

    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-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT