You are visitor number


Nico's Introduction to API Programming for VB

This is the property of  Nico Michael . This information is my original work and may not be reproduced  without my prior consent.


Contents

  1. Introduction
  2. Starting the API Text Viewer Program
  3. Selecting the win32api text file
  4. Selecting and adding functions of API objects
  5. Creating wrapper functions around API Calls
  6. Creating wrapper classes around API calls
  7. The Win32api.txt file

Go to Top


1 Introduction

Go to Top



2 Starting the API Text Viewer 

Start the API Text Viewer from the Visual Basic Folder

wpe2.jpg (110984 bytes)

Go to Top


3 Selecting the Win32api Text File

In the WINAPI directory you will find a file      WIN32API.TXT   

From the file menu choose   Load Text File    and select WIN32API.TXT

wpe3.jpg (52445 bytes)

Go to Top


4 Selecting and adding functions of API objects

In the Avaniable Items List Box  select the desired Item/Function (Beep)

and press the Add button

Press the Public or Private Option Button to declare the functions publically or privately

wpe4.jpg (56024 bytes) 


Go to Top


 

 

 

 

 

 

 

 

 

 

 

 

 

5 Creating wrapper functions around the API  Calls

In the API Text Viewer in the Select Items text box you highlight the Function generated

and paste it into your code above your wrapper function to declare the API Function

 

Public Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As              String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long,                               lpTotalNumberOfClusters As Long) As Long

Function MyDiskFreeSpaceBytes ( sPath as String ) as Double

    Dim sDrive As strting

    Dim lReturn as Long

    Dim I1 ' Sectors per Cluster

    Dim I2 ' Bytes per Sector

    Dim I3 'Number of Free Clusters

    Dim I4 'Total number of Clusters

    sDrive=Left(sPath,1) & ":\"

    IReturn=GetDiskFreeSpace (I1,I2,I3,I4 )

    MyDiskFreeSpaceBytes =I1*I2*I3

End Function

 

Go to Top


6 Creating a Wrapper Classes around API calls
Add a Class to you project in the class you decalre the API Call as Private and

declare your wrapper functions as public

Option Explicit

Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

Public Function lBeep(ByVal lFreeq As Long, ByVal lDuration As Long)
        lBeep = Beep(lFreeq, lDuration)
End Function

You call the API calls by using object instances of your Class

Go to Top

 


WB01339_.gif (896 bytes)Return to Nico's Visual Basic Page

        (http://www.geocities.com/SiliconValley/Peaks/2852/VB_Charts.html)

 

Send mail to The Web Master  with questions or comments about this web site.
Web Page designed by  Web Page Designed by Nico Michael using MS Front Page
Last modified: February 20, 2000
The number of times this Home Page has been accessed is

This page hosted by Get your own Free Home Page

Hosted by www.Geocities.ws

1