Liberty BASIC Help Online

CALLDLL #handle, "function", param1 as type1 [, param2 as type2 ], return as returnType
CALLDLL is used to call functions from the Windows API or from a third party DLL.  A DLL is a Dynamic Link Library, which is a module containing functions that can be called by a program while it is running.  The functions are specific to the DLL.  The documentation for the DLL will contain the information needed to call its functions.
This parameter is the handle that was given to the DLL when it was opened with the OPEN statement.
This parameter is the name of the function, enclosed in quotes.  It is case-sensitive.
param1 as type1 [, param2 as type2 ]
This is a list of input parameters required by the function.  The number and TYPE of input parameters is dependent upon the function being called. These parameters send information to the function so that it knows how to perform its task as needed by the program.  These parameters must be passed AS TYPE.  See Using Types with STRUCTS and CALLDLL for details. The parameters will include information such as window or control handles, text strings to display, and so on.
return as returnType
This parameter contains the value returned by the function.  It must also be of the correct TYPE expected by the function.  If a function does not return a value, this parameter is passed AS VOID.
This example calls the WINDOWS API to minimize a window and change its caption.
    open "An Example" for window as #main
    h = hwnd(#main)
    open "user32" for dll as #user
    calldll #user, "CloseWindow", _
        h as long, _
        result as boolean
    calldll #user, "SetWindowTextA", _
        h as long, _
        "I was minimized!" as ptr, _
        result as void
    close #user
Liberty BASIC 3 has Enhanced DLL handle resolution. If a program hasn't opened certain default DLLs, a reference to a like-named handle will still resolve to the desired DLL.  This saves on code to open and close DLLs.  DLLs can still be opened with the OPEN statement.
Here are the default handles.
'OPEN the DLL and give it a handle
Open "user32" for DLL as #u
Calldll #u, "CloseWindow", h as long, result as boolean
close #u
'call the dll by its default handle.
'no need to OPEN it or CLOSE it
Calldll #user32, "CloseWindow", h as long, result as boolean
See also:  STRUCT, Using Types with CALLDLL, What are APIs/DLLs?, How to Make API Calls

Copyright (C) 2003 Shoptalk Systems
Liberty BASIC -