Im trying to learn api
declare function publicname lib "libname" _ <--I understand
Alias "alias" Byval variable as type <--- don't understand
can any help expain?
what do i treat the returned data as?
Printable View
Im trying to learn api
declare function publicname lib "libname" _ <--I understand
Alias "alias" Byval variable as type <--- don't understand
can any help expain?
what do i treat the returned data as?
Am new too api as well but ill give it a shot.
Ok the (ByVal As Variable as type) means
Whatever you set the variable in the type declaration like this
Public type Woah
Integer * 25 <--- thats the The value that the api uses
End Type
Hope i made sense.. :)
1) The libname is the library in which the API function is in.
2) ByVal simply means that you are passing a copy of the value. When using API's, always pass arguments with ByVal.
3) Most API's have a return value of 0 (if an error occured) or 1 (if it was a success). Others such as FindWindow will return important information, such as the handle of a window.
The Alias keyword is very important for the Win32 API. Basically, it means that if you have:
...then in the DLL, the function is called WindowsFuncA, but you would rather refer to it as WindowsFunc. Many functions in the API have two versions, an A version, and a W version. The 'A' is for ANSI (Windows 9x), and the 'W' is for Wide (Unicode on NT).Code:Private Declare Function WindowsFunc Lib "kernel32" Alias "WindowsFuncA" () As Long
Alias is also important because many functions have names which are illegal in VB so you can provide one that's legal. For example it might be a reserved word or contain characters which can't be used ( such as starting with a _ ).
A really good place to look at these declarations is on the MSDN CD, under books. 'Hardcore VB' gives a thorough and clear explanation of how to create declarations from just the C export info. Well worth reading.