QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The DECLARE LIBRARY declaration allows the use of external library SUB and FUNCTION procedures supported by QB64.

Syntax

DECLARE [DYNAMIC CUSTOMTYPE STATIC] LIBRARY [{“Library_filename” “Headerfile”}]
{SUB FUNCTION} [procedure_name ALIAS] library_procedure ([BYVAL] parameter AS, …)

… ‘other SUBs or Functions as required

END DECLARE

Parameter(s)

Library Types

Description

Example(s)

Using an SDL library procedure as a program SUB procedure to move the mouse pointer to a coordinate (works in versions prior to 1.000):


DECLARE LIBRARY
  SUB SDL_WarpMouse (BYVAL column AS LONG, BYVAL row AS LONG) 'SDL procedure name
END DECLARE
SCREEN _NEWIMAGE(640, 480, 256)  'simulate screen 12 with 256 colors
RANDOMIZE TIMER

DO
  _DELAY 1
  x = RND * 640: y = RND * 480
  LINE (x, y)-STEP(10, 10), RND * 100 + 32, BF
  MouseMove x + 5, y + 5
LOOP UNTIL LEN(INKEY$)  'any keypress quits
END

SUB MouseMove (x AS LONG, y AS LONG)
SDL_WarpMouse x, y     'call SDL library procedure
END SUB 

Explanation: The SDL Library is included and loaded with QB64 versions prior to 1.000, so these procedures are directly available for use.

Using ALIAS to create a program SUB or FUNCTION using QB64 SDL ONLY


SCREEN 12
DECLARE LIBRARY
  SUB MouseMove ALIAS SDL_WarpMouse (BYVAL column&, BYVAL row&)
END DECLARE

_DELAY 2
MouseMove 100, 100
_DELAY 2
MouseMove 200, 200 

Explanation: When a Library procedure is used to represent another procedure name use ALIAS instead. Saves creating a SUB!

Don’t know if a C function is defined by C++ or QB64? Try using empty quotes.


DECLARE LIBRARY ""
    FUNCTION addone& (BYVAL value&)
END DECLARE 

Explanation: The C function ‘addone’ exists in a library QB64 already links to, but it hasn’t been defined as a C function or a QB64 function. By using “” we are telling QB64 the function exists in a library which is already linked to and that it must define the C function before calling it, as well as allowing QB64 code to call it. Trying the above code without the “” will fail.

Note: Which libraries are or aren’t automatically used in the linking process is not formally defined, nor is it guaranteed to stay that way in future versions of QB64.

QB64 version 1.000 and up produce standalone executables. External DLL files must be distributed with your program.

See Also