Declare Definition
Syntax
[ | Private | Public ] _ Declare Sub name Lib "dll name" _ [Alias "module name"] [([param[, ...]])] -or- [ | Private | Public ] _ Declare Function name[type] Lib "dll name" _ [Alias "module name"] [([param[, ...]])] [As type[()]]
Group
Description
Interface to a DLL defined subroutine or function. The values of the calling arglist are assigned to the params.
Err.LastDLLError returns the error code for that last DLL call.
Access
If no access is specified then Public is assumed.
Pocket PC
Not supported.
Sandbox
Sandbox mode blocks this definition.
Parameters | Description |
---|---|
name | This is the name of the subroutine or function being defined. If Alias "module name" is omitted then this is the module name, too. |
"dll name" | This is the DLL file where the module's code is. If the DLL is in the same directory as the macro/module the expression MacroDir & "dll name" is allowed. This is the only expression other than a string constant which is allowed. |
"module name" |
This is the name of the module in the DLL file.
If this is #number then it is the ordinal number of the module.
If it is omitted then name is the module name.
The DLL is searched for the specified module name. If this module exists, it is used. All As String parameters are converted from Unicode to ASCII prior to calling the DLL and from ASCII to Unicode afterward. (Use Unicode:module name to prevent ASCII to Unicode conversion.) If the module does not exist, one or two other module names are tried:
If none of these module names is found a run-time error occurs. |
params |
A list of zero or more params that are used by the
DLL subroutine or function.
NOTE: A ByVal string's value may be modified by the DLL.
|
Example
Declare Function GetActiveWindow& Lib "user32" () Declare Function GetWindowTextLengthA& Lib "user32" _ (ByVal hwnd&) Declare Sub GetWindowTextA Lib "user32" _ (ByVal hwnd&, ByVal lpsz$, ByVal cbMax&) Function ActiveWindowTitle$() ActiveWindow = GetActiveWindow() TitleLen = GetWindowTextLengthA(ActiveWindow) Title$ = Space$(TitleLen) GetWindowTextA ActiveWindow,Title$,TitleLen+1 ActiveWindowTitle$ = Title$ End Function Sub Main Debug.Print ActiveWindowTitle$() End Sub