Super Code from Digital Knife Monkey Productions

Digital Knife Monkeys at Keyboards...Will Eventually Program Everything.

Declare Library

Declare library is a command unique to QB64 which allows you to link libraries to your code and use the functions and subprograms in the library in your code. doing this allows you access capabilities which are not native to QB64.

Declare Library comes in two forms: Declare Library and Declare Dynamic Library.

with the exception of SDL one uses DECLARE DYNAMIC LIBRARY to utilize DLLs.

Under the current situation one needs a helper function to deal with pointers.

you can either create it yourself and name it whatever you want as long as its as a header file IE: .h or a full fledged library.

 the basic form of the code required to be in the header is in C form and needs to be structured as so:

inline SDL_Joystick* SDL_JOYSTICK_POINTER(int64 x){return (SDL_Joystick*)x;}

Where the things in red can have different names this is required to handle the pointers or you can just download the working joystick.h file that this tutorial uses.

Now when sending parameters to a sub or function that exists in an external library it is best to do so with an equal size value.

   DECLARE [DYNAMIC] LIBRARY ["Library_name"]
     {SUB|FUNCTION}[procedure_name ALIAS] library_name (BYVAL parameter(s))
   END DECLARE

[source QB64 wiki] 

EXAMPLE:

DECLARE LIBRARY
   FUNCTION SDL_InitSubSystem (BYVAL flags AS _UNSIGNED LONG)
   FUNCTION SDL_NumJoysticks ()
   FUNCTION SDL_JoystickOpen&& (BYVAL indx AS LONG)
   FUNCTION SDL_JoystickName$ (BYVAL flag AS INTEGER)
   FUNCTION SDL_JoystickIndex&& (BYVAL joint AS INTEGER)
   FUNCTION SDL_JoystickNumAxes% (BYVAL glas AS _UNSIGNED _INTEGER64)
   FUNCTION SDL_JoystickNumButtons% (BYVAL Fls AS _UNSIGNED _INTEGER64)
   FUNCTION SDL_JoystickEventState (BYVAL state AS _UNSIGNED INTEGER)
   FUNCTION SDL_JoystickGetAxis% (BYVAL Fls AS _INTEGER64, BYVAL axis AS LONG)
   FUNCTION SDL_JoystickGetButton% (BYVAL Fls AS _INTEGER64, BYVAL axis AS LONG)
   FUNCTION SDL_JoystickGetHat~% (BYVAL fls AS _INTEGER64, BYVAL hat AS LONG)
   SUB SDL_JoystickUpdate ()
END DECLARE
DECLARE LIBRARY "joystick"
   FUNCTION SDL_JOYSTICK_POINTER&& (BYVAL Offset AS _INTEGER64)
END DECLARE

Loading functions from a library

to load a function from a library you need to follow the basic format of:

Using SDL functions and subs

now with the case of SDL functions and subs you have to know the  values it requires you can find this information by looking into the pertinent header file in the case of joysticks sdl_joystick.h.

Values for activating sdl subsystems:

CONST SDL_INIT_TIMER = &H1
CONST SDL_INIT_AUDIO = &H10
CONST SDL_INIT_VIDEO = &H20
CONST SDL_INIT_CDROM = &H100
CONST SDL_INIT_JOYSTICK = &H200
CONST SDL_INIT_NOPARACHUTE = &H100000 '/* Don't catch fatal signals */
CONST SDL_INIT_EVENTTHREAD = &H1000000 '/* Not supported on all OS's */
CONST SDL_INIT_EVERYTHING = &HFFFF

these are the values to input into the SDL_InitSubSystem function which returns a 0 on success and a 1 on failure. these values can be OR'd together as such:

PRINT SDL_InitSubSystem(SDL_INIT_VIDEO OR SDL_INIT_CDROM).