<< Click to Display Table of Contents >> Navigation: ThinBASIC SDK > Anatomy of thinBASIC module |
All thinBASIC modules must adhere to the following rules.
Naming convention
Even custom thinBASIC modules must follow the naming convention of thinBasic_*.dll.
Examples using this convention:
othinBasic_MyModule.dll
The example above can be then imported the following way, as long as you copy it to thinBASIC/Mod or thinBASIC/Lib directory:
uses "MyModule"
Exported functions
In order to make the DLL being recognised by thinBASIC as a module, it must export some mandatory functions.
For interface version 1:
oLoadLocalSymbols
oUnLoadLocalSymbols
For interface version 2:
oLoadLocalSymbols_V2
oUnLoadLocalSymbols_V2
Minimal module implementation
An minimal thinBASIC module implementation in PowerBASIC for Windows can be as simple as:
#COMPILE DLL "thinbasic_myModule.dll" ' Ensure module name according to convention
'----------------------------------------------------------------------------
#INCLUDE "thinCore.inc" ' Include thinCore bindings
'----------------------------------------------------------------------------
SUB myModule_func() ' Implement custom FUNCTION/SUB
MSGBOX "Hello, I am func!"
END SUB
'----------------------------------------------------------------------------
' Mandatory function for V1 interface - providing initialization and exposing functionality
FUNCTION LoadLocalSymbols ALIAS "LoadLocalSymbols" ( OPTIONAL BYVAL sPath AS STRING ) EXPORT AS LONG
' Provide module function
thinBasic_LoadSymbolEx "myModule_func", %thinBasic_ReturnNone, CODEPTR(exec_myModule_func), %thinBasic_ForceOverWrite, "myModule_func()", "Does nothing"
' Provide module numeric equate
thinBasic_AddEquate "%MYMODULE_VALUE", "" , 42
' Provide module string equate
thinBasic_AddEquate "$MYMODULE_TEXT" , "Hello" , 0
FUNCTION = 0
END FUNCTION
'----------------------------------------------------------------------------
' Mandatory function for V1 interface - cleanup
FUNCTION UnLoadLocalSymbols ALIAS "UnLoadLocalSymbols" ( ) EXPORT AS LONG
FUNCTION = 0
END FUNCTION
'----------------------------------------------------------------------------
' Standard Win32 DLL LibMain
FUNCTION LIBMAIN ALIAS "LibMain" ( BYVAL hInstance AS LONG, BYVAL fwdReason AS LONG, BYVAL lpvReserved AS LONG ) EXPORT AS LONG
SELECT CASE fwdReason
CASE %DLL_PROCESS_ATTACH
FUNCTION = 1&
EXIT FUNCTION
CASE %DLL_PROCESS_DETACH
FUNCTION = 1&
EXIT FUNCTION
CASE %DLL_THREAD_ATTACH
FUNCTION = 1&
EXIT FUNCTION
CASE %DLL_THREAD_DETACH
FUNCTION = 1&
EXIT FUNCTION
END SELECT
END FUNCTION