In the previous article, we explained a simplest example. Maybe you will have some ideas: You can find the function directly in the VB API Viewer, why do you want to call directly? In fact, API Viewer The statement that can be output is limited. We can't always depend on it. Open the VS installation directory common file under the common file under CommON / Tools / WinApi, you can see a lot of API functions in its inside, original The API declarations that the API Viewer generated are from this file. There are some statements that are commonly used in this file. But not all. Many times, hand-written is necessary. Such as calling the external SDK Dynamic link library Or when some system deep API functions.
The format of the API function declaration:
[Private | Public] DECLARE FUNCTION | SUB Function Name lib "library name" [alias "alias"] (parameter list) [AS return value type]
The red content is system reserved word. [] Is optional.
PRIVATE | PUBLIC Table API Function Scope: Private or Shared.
Function | Sub Table API Function Type Function is a function SUB as a process (function of no reference to the value needs to be converted to this type)
Lib "library name" table API function The library file file name and path are located.
[Alias "Alias"] Table API function alias, when the API function is renamed with a keyword, you can use this parameter.
(Parameter list) BYVAL table value reference, byref table address reference (*), default is byref.
[AS Return Value Type] Table API Returns Type
Example: A.dll file (existing in D: /) in a SDK is provided. One of the functions C prototypes are as follows:
Int Add (Int A, INT B);
We do the following statement:
Public Declare Function Add "D: /A.dll" (BYVAL A As Long, BYVAL B AS Long) As long
For the SDK API function you often use, you can make an API declaration file. Format can be written in the format of Win32api.txt above. You can use the API Viewer to call them directly. For Win32API.txt In the system deep API function, you can also add it to your own use.