How to manually declare API
Transfer from: VB enthusiastist ---------------------------------------------------------------------------------------------------------------------------------- ------------------------------------ Although Visual Basic provides a lot of Win32API.txt The predefined declaration, but it still needs to know how to write a declaration personally. For example, sometimes you want to access the procedures in the DLL written in other languages, or rewrite the Predefined statement for Visual Basic to meet special needs. To declare an API process, you need to add a Declare statement in the "Declaration" section of the code window. If the process returns a value, it should be declared as function: Declare function publicname lib "libname" [alias "alias"] [([Byval] variable [as type] [, [byval] variable [as type]]. ..])] If the process does not return a value, it can declare it as sub: Declare Sub publicname lib "libname" [alias "alias"] [([Byval] variable [as type] [, [Byval] variable [As Type]] ...]) By default, the API process declared in the standard module is public, and it can be called anywhere in the application. The API process defined in other types of modules is the module private, and must distinguish between the private keywords in front to distinguish. 1. Specify the lib clause in the library Declare statement to tell Visual Basic how to find a .api file containing the process. If the referenced process belongs to the Windows core library (user32, kernel32 or gdi32), you may not include a file extension: Declare Function GetTickCount Lib "kernel32" Alias _ "gettickcount" AS Long For other DLLs, lib clauses specify files Path: DECLARE FUNCTION LZCOPY LIB "C: /WINDOWS/LZEXPAND.API" _ (Byval S AS Integer) AS Long If the path of libName is not specified, Visual Basic will find the file in the following order: .exe file The current directory current directory Windows bit system directory (usually / windows / system) Windows directory (not necessarily / windows) PATH environment variable 2. Processing Windows API procedure using strings If the calling Windows API process should be used String, then an Alias clause must be added in the declaration statement to specify the correct character set. The Windows API function containing the string actually has two formats: ANSI and Unicode. Therefore, in the Windows header file, each function containing a string has an ANSI version and Unicode version. For example, the following is two C language descriptions of the SetWindowText function.