In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the use of the VB API function?" in the operation of actual cases, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
First, there are two ways to declare the API function in the use of the VB function
If we only use the API function in a form, we can declare it in the General section of the form code:
The syntax of the declaration is:
Private Declare Function... Private Declare Sub.
The Private declaration must be used here, because this API function can only be called by a program within a form.
If our program is made up of multiple forms and we need to use the same API function in multiple forms, we need to declare it in the module.
Add a module first, and then declare it using the following syntax:
Public Declare Function.... Public Declare Sub....
The meaning of the Public declaration is to treat the API function as a public function or procedure that can be called directly from anywhere in a project (including all forms and modules). After the declaration, we can use this API function in the program.
2. You can use the API function in the following ways, taking the SetWindowPos function as an example:
(1) ignore the call to the return value of the function:
SetWindowPos Form1.hWnd,-2,0,0,0,0,3
Note that the parameters of the function are unparenthesized at this time.
(2) call the Call method:
Call SetWindowPos (Form1.hWnd,-2,0,0,0,3)
(3) the call to get the return value of the function:
MyLng = SetWindowPos (Form1.hWnd,-2,0,0,0,3)
Parentheses are needed at this point, and we must define a variable in advance (the variable is of the same type as the function's return value) to store the return value of the API function.
3. Explanation of several questions:
(1) what happened to Lib and Alias in the statement
In general, the WIN32API function is always included in the DLL that comes with the WINDOWS system or provided by other companies, and the Lib keyword in the Declare statement is used to specify the path of the DLL (dynamic link library) file, so that VB can find the DLL file and then use the API function in it. If we only list the name of the DLL file without indicating its full path, VB will automatically search for the DLL file in the .exe file directory, the current working directory, the WINDOWS\ SYSTEM directory, and the WINDOWS directory. So if the DLL file you want to use is not in the above directories, we should specify its full path.
Alias is used to specify the alias of the API function, and the Alias keyword is required if the API function we are calling is going to use a string (the argument contains a string). This is because the name of the same API function may be different in the ANSI and Unicode character sets. In order to ensure that there are no declaration errors, we use the Alias keyword to indicate the alias of the API function. Generally speaking, on the WIN9X platform, we can use the API function name followed by an uppercase An as an alias.
(2) description of common API parameter types
The most common parameter of the API function is the long long data type, such as the handle in API, some specific constants, and the return value of the function are all values of this type; other common parameter types are: integer Integer, Byte, string, and so on.
(3) what is the purpose of the ByVal in the statement
This is related to the parameter transfer mode of VB. By default, VB passes the parameters of the function by address, while some API functions require that the parameters of the function must be passed by value (the two methods of parameter transfer are different: the former passes a pointer, while the latter requires the real value of the parameter). An error occurs, and the solution is to precede the parameter declaration of the API function with the ByVal keyword, so that VB passes the parameter by value.
(4) how to get a complete API function declaration
VB comes with the API text viewer API TEXT VIEWER, where you can find the full declaration of the API function and paste it into the program.
This is the end of the content of "how to use the VB API function". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.