hello.
perhaps somebody can check the "powerbasic" code for my "graphx" example. it's just a test how to understand building a thinbasic module coming from powerbasic. I have some ideas for sdk windows or other graphic input things, I am not quite sure, but want to try it to realize...
I have done some mistakes in pb code, I am sure, but wanted to do this experiment.
demo: powerbasic code
[code=thinbasic] #IF 0
=============================================================================
Program NAME: UserDefinedLib.bas
Author : Eros Olmi
Version :
Description : DLL TO test thinBasic loading library
=============================================================================
'COPYRIGHT AND PERMISSION NOTICE
'============================================================================
Copyright (c) 2003 - 2009, Eros Olmi, <eros.olmi@thinbasic.com>
ALL rights reserved.
Permission TO use this software IS granted ONLY FOR the purpose TO develop
thinBasic language modules both FOR commercial OR non commercial purpose.
IN ANY CASE the above copyright notice AND this permission notice must appear
IN ALL copies.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
=============================================================================
#ENDIF
#COMPILE DLL
#REGISTER NONE
#DIM ALL
'---Resource file. Change UserDefinedLib.RC resource file as needed and remember to compile
' into UserDefinedLib.PBR file using resource compiler
#RESOURCE "UserDefinedLib.PBR"
#INCLUDE "WIN32API.INC"
'---Every used defined thinBasic module must include this file
#INCLUDE "thinCore.inc"
%ButtonClose = 1001
'----------------------------------------------------------------------------
FUNCTION Exec_HEX() AS STRING
' Return a string that is the hexadecimal (base 16) representation of its argument.
' Usage: s$ = HEX$(numeric_expression [, digits])
'----------------------------------------------------------------------------
LOCAL lNumber AS EXT
LOCAL lDigits AS EXT
'---Here we have to parse the syntax we have decided this new keyword will have
' Syntax is: an open pares
' followed by a numeric expression
' followed by an optional comma with an optional numeric expression
' a close parens
'---Here how to do
'---Parse open pares
IF thinBasic_CheckOpenParens() THEN
'---If ok, parse a numeric expression and return it's value.
' Remember to always use EXT numeric type even if you need a different one
thinBasic_ParseNumber lNumber
'---Here we see if there is a comma.
' If not, we have instruct not to produce a runtime error and to put back
' the found token into the parsing stack
IF thinBasic_CheckComma(%TRUE, %TRUE) THEN
'---If optional comma was specified we parse another numeric expression
thinBasic_ParseNumber lDigits
END IF
'---At the end check if close parens was specified
IF thinBasic_CheckCloseParens() THEN
'---At the end here we are. If optional parameter was specified, call the function
' with the optional parameter
IF lDigits > 0 THEN
FUNCTION = HEX$(lNumber, lDigits)
ELSE
'---otherwise call function without optional parameter
FUNCTION = HEX$(lNumber)
END IF
END IF
END IF
END FUNCTION
'######################################################################################################
FUNCTION Exec_windowMe (BYVAL hdlg AS LONG, BYVAL windox AS LONG, BYVAL cbDialox AS LONG) AS Ext 'LONG
DIM a AS LONG
DIM b AS LONG
DIALOG NEW 0, "Frankos_Test_Dialogue",-1,-1, 330, 203, _
%WS_POPUP OR _
%WS_VISIBLE OR _
%WS_CLIPCHILDREN OR _
%WS_CAPTION OR _
%WS_SYSMENU OR _
%WS_MINIMIZEBOX, _
0 TO hDlg
CONTROL ADD BUTTON, hDlg, %ButtonClose, "Click to kill me softly", 90, 50, 150, 100
DIALOG SHOW MODAL hDlg CALL cbDialog
IF thinBasic_CheckOpenParens() THEN
thinBasic_ParseLong hDlg
IF thinBasic_CheckOpenParens() THEN
thinBasic_ParseLong windox
IF thinBasic_CheckCloseParens() THEN
windox = %TRUE
IF thinBasic_CheckCloseParens() THEN
hdlg = %TRUE
IF hDlg THEN windox = %buttonclose
FUNCTION = windox
END IF
END IF
END IF
END IF
END FUNCTION
'######################################################################################################
'------------------------------------------------
' Callback function used to handle dialog events
'------------------------------------------------
CALLBACK FUNCTION cbDialog() AS LONG
SELECT CASE CBMSG
CASE %WM_COMMAND
IF CBWPARAM = %ButtonClose THEN DIALOG END CBHNDL
CASE %WM_DESTROY
MSGBOX "Window is to be destroyed.", %MB_OK, "tbGraphx_yes!"
END SELECT
END FUNCTION
'----------------------------------------------------------------------------
FUNCTION Exec_Console_FColor() AS EXT
' Compose a new console foreground color.
' Usage: n = Console_fColor ( R AS LONG, G AS LONG, B AS LONG, Intense AS LONG)
'----------------------------------------------------------------------------
LOCAL R AS EXT, lR AS LONG
LOCAL G AS EXT, lG AS LONG
LOCAL B AS EXT, lB AS LONG
LOCAL Intense AS EXT, lIntense AS LONG
LOCAL ForeColor AS LONG
IF thinBasic_CheckOpenParens() THEN
thinBasic_ParseNumber R
IF thinBasic_CheckComma() THEN
thinBasic_ParseNumber G
IF thinBasic_CheckComma() THEN
thinBasic_ParseNumber B
IF thinBasic_CheckComma() THEN
thinBasic_ParseNumber Intense
IF thinBasic_CheckCloseParens() THEN
lR = R
lG = G
lB = B
lIntense = Intense
IF lR THEN ForeColor = %FOREGROUND_RED
IF lG THEN ForeColor = ForeColor OR %FOREGROUND_GREEN
IF lB THEN ForeColor = ForeColor OR %FOREGROUND_BLUE
IF lIntense THEN ForeColor = ForeColor OR %FOREGROUND_INTENSITY
FUNCTION = ForeColor
END IF
END IF
END IF
END IF
END IF
END FUNCTION
SUB Exec_tbgraphx_Test
LOCAL VPTR AS LONG
LOCAL VAbsPos AS LONG
LOCAL myValue AS EXT
VPTR = 123456789
IF thinBasic_CheckOpenParens( ) THEN
thinBasic_VariableParse(VPtr, VAbsPos)
IF thinBasic_CheckCloseParens( ) THEN
MSGBOX STR$ (VPtr) & "," & STR$ (VAbsPos) & ", [" & "]", , "tbGraphx"
MyValue = 2009
thinBasic_ChangeVariableNumberDirect (VPtr, VAbsPos, MyValue)
END IF
END IF
END SUB
'----------------------------------------------------------------------------
FUNCTION LoadLocalSymbols ALIAS "LoadLocalSymbols" (OPTIONAL BYVAL sPath AS STRING) EXPORT AS LONG
' This function is automatically called by thinCore whenever this DLL is loaded.
' This function MUST be present in every external DLL you want to use
' with thinBasic
' Use this function to initialize every variable you need and for loading the
' new symbol (read Keyword) you have created.
'----------------------------------------------------------------------------
'---
'Add here Initialization code if needed
'---
'---
'Here define/add new thinBasic keywords
'---
'---Here an example. Defined a new keyword named HEX$ which will return a string.
' Connect this keyword with Exec_HEX internal function passing its pointer with CODEPTR.
' Last parameter tells thinBasic that even if HEX$ keyword has already been defined, this new
' definition will have priority and will overwite previous keyword configuration
thinBasic_LoadSymbol "MyHEX$", %thinBasic_ReturnString, CODEPTR(Exec_HEX), %thinBasic_ForceOverWrite
thinBasic_LoadSymbol "Console_fColor", %thinBasic_ReturnNumber, CODEPTR(Exec_Console_FColor), %thinBasic_ForceOverWrite
thinBasic_LoadSymbol "tbGraphx_Test", %thinBasic_ReturnNone, CODEPTR(Exec_tbGraphx_Test ), %thinBasic_ForceOverWrite
thinBasic_LoadSymbol "windowMe", %thinBasic_ReturnCodeLong, CODEPTR(Exec_windowMe ), %thinBasic_ForceOverWrite
'---
'Here define/add new thinBasic equates
'---
thinBasic_AddEquate "%MyNumericEquate", "" , 1
thinBasic_AddEquate "$MyStringEquate", "ABC" , 0
END FUNCTION
'----------------------------------------------------------------------------
FUNCTION UnLoadLocalSymbols ALIAS "UnLoadLocalSymbols" () EXPORT AS LONG
' This function is automatically called by thinCore whenever this DLL is unloaded.
' This function CAN be present but it is not necessary. If present, this function
' will be executed by thinBasic core when module will be released.
' Use this function to perform uninitialize process, if needed.
'----------------------------------------------------------------------------
'---
'Add here DeInitialization code if needed
'---
FUNCTION = 0&
END FUNCTION
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
[/code]
here the thinbasic test code:
[code=thinbasic]MODULE "graphx" '
uses "console"
dim res as long
dim u as ext
dim x,y,z as long
dim s as string
tbGraphx_Test(u)
res = Msgbox(0, "Ute was born in:" & str$(u))
x = msgbox 0, "color_value: " + Console_fColor(1,2,3,4)
printl "color_value: " + Console_fColor(1,2,3,4)
z = msgbox 0, "hex_value: " + MyHex$(2,4)
printl "hex_value: " + MyHex$(2,4)
y = msgbox 0, "window: " + windowMe(1,2,3), %MB_OK, "graphx_test value: "
[/code]
would be nice if somebody can tell what's the main reason I have got the gpf
to check the code it isn't so important to do this one fast. I can wait.
best regards, Frank
Bookmarks