May 19th, 2010, 09:04 AM
[VB6] What Is The API?
Q: What Is The API?
A: The Windows API is a set of several hundred functions and subroutines that are located in a set of files called Dynamic Link Libraries (DLLs). You can make a function from the Windows API available to your Visual Basic program by declaring the function to be callable from your program. You can then use the Windows API function as you would any built-in Visual Basic function or a function that you have written yourself.
Q: Can Anyone Use The API, And Why Should We use It?
A: End users cannot access these functions; however, programmers can access the code written in the DLLs through the API and use this code in their programs. This enables you to use existent code in the DLLs and save you time in the programming development cycle. The advantage of using Windows APIs in your code is that they can save development time because they contain dozens of useful functions that are already written and waiting to be used. The disadvantage is that Windows APIs can be difficult to work with and unforgiving when things go wrong.
Q: Where Can I Find These Files That Contain The APIs?
A: The Dynamic Link Library (DLL) files that make up the Windows API are commonly located in the Windows SYSTEM subdirectory. These files are found on every PC that is running Windows, so you don't have to worry about including them if you create a set of setup disks for distribution. The three Windows DLLs are User32.DLL, Kernel32.DLL , and GDI32.DLL. Several smaller DLLs, known as Extension DLLs, provide functions in addition to those found in the three major DLLs. Some useful extension DLLs include the following:
Q: Now, How Can I Get These APIs Into My VB 6 Program?
A: To include a Windows API function in your VB6 programs, use the Declare statement to "declare" the function to be part of your program. The Declare statement is added to the General Declarations section of either a standard module or a form. If the Declare statement is added to a standard module, the function is considered Public and can be called from anywhere in your application. If the Declare statement is added to the General Declarations section of a form, the function is local to that form and can be called only from within that form. In the latter case, you need to include the Private keyword.
Q: What Would The Syntax Look Like?
A: The syntax of the Declare statement depends on whether or not the procedure you call returns a value. If the procedure does return a value, you use the Function form of the Declare statement:
[code][Public | Private] Declare Function publicname Lib "libname" _
[Alias "alias"] [([[ByVal | ByRef] argument [As Type] _
[, [Byval | ByRef] argument [As Type]] ...])] [As Type]
Or A Better example :
Q: Is There An Easier Way, Or Should I Memorise Every Single Character?
Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long
A: Yes, there is a much easier way Use the API Viewer which is included with the VB 6 package :
Here's How :
To view an API file
From the Add-Ins menu, open the Add-In Manager, and load WinAPI Viewer.
Click WinAPI Viewer from the Add-Ins menu.
Open the text or database file you want to view.
To load a text file into the viewer, click File | Load Text File, and choose the file you want to view.
More Information On The Implemtation Of APIs In VB 6, Can Be Found Here
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!