Declare Definition
Syntax
Declare Sub name Lib "dll name" _
[Alias "module name"] [([param[, ...]])]
-or-
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.
WARNING! Be very careful when declaring DLL subroutines or functions. If you make a mistake and declare the parameters or result incorrectly then Windows might halt. Save any open documents before testing new DLL declarations.
Err.LastDLLError returns the error code for that last DLL call.
Access
Public is assumed if access is omitted.
Parameters |
Description |
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, 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.
|
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.) |
See Also
Example
Option Explicit
Declare Function GetActiveWindow Lib "user32" () As PortInt
Declare Function GetWindowTextLength Lib "user32" _
(ByVal hwnd As PortInt) As Long
Declare Sub GetWindowText Lib "user32" _
(ByVal hwnd As PortInt, ByVal lpsz As String, ByVal cbMax As Long)
Function ActiveWindowTitle() As String
Dim ActiveWindow As PortInt
ActiveWindow = GetActiveWindow()
Dim TitleLen As Long
TitleLen = GetWindowTextLength(ActiveWindow)
Dim Title As String
Title = Space(TitleLen)
GetWindowText ActiveWindow, Title, TitleLen+1
ActiveWindowTitle = Title
End Function
Sub Main
Debug.Print ActiveWindowTitle()
End Sub