I keep reading about them in the forums but I don't understand what they are. I'm sorry.
Printable View
I keep reading about them in the forums but I don't understand what they are. I'm sorry.
Application Program Interface. A set of routines provided in libraries that extends a language's functionality.
To undestand what API is, you must have a basic knowledge of VB Functions. A quik look at vb functions follows.
You create a function in vb to perform a repetitive task for you. example,
The above function displays a message box with whatever the Greeting Text you supply.to call this function in your application, you just specify its name and pass the greeting text to it. To call the above function in anywhere in the vb code, you would do like thisCode:public function greet(GreetString as string)
msgbox GreetString
End function
Simply you specify the function name and pass the parameter to it.Code:Call Greet ("Hapy Birth Day to you")
in this way, you can call the above function as many time as you want by simply specifying the function name and passing it a Greeting String.
The vb msgbox() it self is a vb function. you just call it with its name and pass some paramerts to it. so it displays a message box for you on the screen.
likewise, Windows API's are just special functions written to manipulate the windows operating system written by microsoft. thease API's (functions) are kept in DLL Files you found under system32 directory such as user32.dll, gdi32.dll etc. one dll file may contain many api's (functions). Windows itself uses many of thease API's if i am correct.
Visual Basic provide a way to call thease functions from a vb procedure or from a vb function and performing tasks that the standard vb functions and statement do not permit. for example, vb has no native way to retrive the amount of memory available in your computer system. but you can retrive the amount of memory in the system easily by calling the appropriprate Windows API that retrive the amount of free memory in the system for you.
There are around 950 API's are available in windows (if i am correct) and you can do almost every thing the windows itself do for you. example, you change the screen resolution through the desktop properties windows. but you can still change the resolution of the desktop by simply from your vb application by calling the appropriate disply API and passing the screen resolution to it you want.
What really happen behind the seen when you call an API from your visual basic program,
You to VB : VB, Can you pls tell how much memory is available in this computer
VB to You : OK, Please wait and i will come back to you.
vb to API :- API, Please tell me how much memory is available in this computer.
API to vb : VB, There are 128 MB is available (normly return in bytes) .
VB to API : OK, Thank you.
VB to You : You have 128 MB Ram is availabe in your computer
How to call thease API's from your vb application and how to find the correct api for a perticuler operation etc things are dificult to explain here.
you need to find a good tutorial on the net or better buy some API related books on the market. Most API programmers preferre the following book as there primary source http://www.amazon.com/gp/offer-listi...951476-7319163
Note:-i tryed my best to explain what i know about API's. if there any mistakes hoe the experts will correct it :)
[/CODE]
[QUOTE=Fazi]
The above function displays a message box with whatever the Greeting Text you supply.to call this function in your application, you just specify its name and pass the greeting text to it. To call the above function in anywhere in the vb code, you would do like thisCode:public function greet(GreetString as string)
msgbox GreetString
End function
public function greet should be Sub since we don't expect for a return value, sorry it's just a comment.Code:Call Greet ("Hapy Birth Day to you")
Thanks for the correction Vntalk. It is OK ;)
I'm Newbie of API.
The Win32 API, or Application Programming Interface, is of immense use in extending the power of Visual Basic. The Win32 API is the collection of functions and subroutines that provides programmatic access to the features of the operating system. It allows Visual Basic programmers far greater access to the inner workings of the Windows operating system without having to suffer through the steep learning curve associated with Visual C++ style Windows programmingReference : http://books.google.com.my/books?id=...2B+programming
I read from a book cay called Mastering Visual Basic 6 by Evangelous Petroutsos. The book is explain API is a set of functions developed primarily for C programmers, but we can use it within visual basic application.
We do not need to remeber the arguments of every API function or even the function names. It's assumed you'll look them up in a reference. This reference available from within Visual Bseasic's IDE, and it's the API Viewer.
1) Choose Add-Ins > API Viewer.If the viewer command doesn't appear in the add-Ins menu, select Add-Ins Manager, and in the Add-Ins Manager dialog box double-click the entry Visual Basic 6 API Viewer ti add it to the Add-Ins menu.
2) In the API Viewer window, choose File > Load Text File or File > Load Database File. The Load Database File loads Faster ( Except for the first time, when the test file is converted to a database).
3) In the Available Items list box, select the function yo want, and click the add button. API Viewer displays the selected function(s) in the selected Item list box.
4) Selec the functions you need for your application and then click the copy button to copy the function's declaration to the clipboard.
5) Open your application's Code window and paste in the function declarations.
:thumb: