\<bookmark_value\>Declare statement\</bookmark_value\>

Declare Statement

\<bookmark_value\>DLL (Dynamic Link Library)\</bookmark_value\>

Declares and defines a subroutine in a DLL file that you want to execute from LibreOffice Basic.

See also: FreeLibrary

Syntax:


Declare {Sub | Function} Name Lib "Libname" [Alias "Aliasname"] [Parameter] [As Type]

Parameters:

\<emph\>Name:\</emph\> A different name than defined in the DLL, to call the subroutine from LibreOffice Basic.

\<emph\>Aliasname\</emph\>: Name of the subroutine as defined in the DLL.

\<emph\>Libname:\</emph\> File or system name of the DLL. This library is automatically loaded the first time the function is used.

\<emph\>Argumentlist:\</emph\> List of parameters representing arguments that are passed to the procedure when it is called. The type and number of parameters is dependent on the executed procedure.

\<emph\>Type:\</emph\> Defines the data type of the value that is returned by a function procedure. You can exclude this parameter if a type-declaration character is entered after the name.

Warning Icon

To pass a parameter to a subroutine as a value instead of as a reference, the parameter must be indicated by the keyword \<emph\>ByVal\</emph\>.


Example:


Declare Sub MyMessageBeep Lib "user32.dll" Alias "MessageBeep" ( Long )
Sub ExampleDeclare
Dim lValue As Long
    lValue = 5000
    MyMessageBeep( lValue )
    FreeLibrary("user32.dll" )
End Sub

Please support us!