Please enable JavaScript to view this site.

thinBasic Help Manual

Navigation: ThinBASIC SDK

Anatomy of thinBASIC module

Scroll Prev Top Next More

* * HELP & MANUAL PREMIUM PACK 4 DEMO VERSION * *

This documentation was styled with a demo skin from the Premium Pack 4 add-on for Help & Manual. The contents of the skin are encrypted and not configurable. You can only publish HM projects with this skin. You cannot edit it or change it.

This version is copyright and may only be used for local testing purposes. It may not be distributed.

Please purchase the full version of the Premium Pack to get the configurable skins and remove this notice. The package will also include the Toolbox configuration utility for Premium Pack skins.

 

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

 

 

Created with Help+Manual 8 and styled with Premium Pack Version 4 © by EC Software