View Full Version : thinBasic_Run to start an additional script?
ReneMiner
20-05-2013, 09:11
Can I use function thinBasic_Run Lib "thinCore.dll" to start additional tB-scripts due runtime?
Declare Function thinBasic_Run _
Lib "thinCore.dll" _
Alias "thinBasic_Run" _
( _
ByVal hScript As Long , _
sBuffer As Asciiz , _
ByVal BufferType As Long , _
Optional ByVal Options As Long , _
ByVal DebugMode As Long , _
ByVal LogMode As Long , _
ByVal ObfuscateMode As Long , _
ByVal CallingProgram As Long , _
ByVal DependancyMode As Long _
) As Long
How do I get the hScript-Handle?
And do I have to set sBuffer to the Filename and Buffertype to either %thinBasic_BufferType_IsFile then
or
fill sBuffer with file-content and Buffertype %thinBasic_BufferType_IsScript? Can I just read in the file using File_Load then?
How to make a "normal" String become Asciiz? Just like this:
myAsciiz = Peek$( Asciiz, StrPtr(myString), StrPtrLen(StrPtr(myString)) )
?
Which Optional parameters would I have to set? Which DependancyMode so after loaded the script has ended the "real" script will be continued?
Petr Schreiber
20-05-2013, 10:12
Here is something that almost works hehe, but I think the problem could be thinCore is already loaded by TB.
The example below will run the script, but it will not continue after its quit.
' -- Modules
Uses "File", "Console"
' -- ThinCore access
%thinBasic_BufferType_IsFile = 0
%thinBasic_BufferType_IsScript = 1
Declare Function thinBasic_Init Lib "thinCore.dll" Alias "thinBasic_Init" (ByVal hWnd As Long, ByVal cInstance As Long, ByVal sKey As String) As Long
Declare Function thinBasic_Release Lib "thinCore.dll" Alias "thinBasic_Release" ( ByVal hScript As Long ) As Long
Declare Function thinBasic_Run Lib "thinCore.dll" Alias "thinBasic_Run" (
ByVal hScript As Long ,
ByVal sBuffer As String ,
ByVal BufferType As Long ,
Optional ByVal Options As Long ,
ByVal DebugMode As Long ,
ByVal LogMode As Long ,
ByVal ObfuscateMode As Long ,
ByVal CallingProgram As Long ,
ByVal DependancyMode As Long ) As Long
Function TBMain()
String sScript = APP_Path + "SampleScripts\General\Alert\Alert.tBasic"
If FILE_Exists(sScript) = FALSE Then
MsgBox 0, "Could not find " + sScript + $CRLF(2) + "Program will end now"
Stop
End If
Print "Initializing..."
Long hScript = thinBasic_Init(0, GetCurrentInstance, "")
PrintL "DONE"
If (MsgBox(0, "Do you want to execute from file?", %MB_YESNO) = %IDYES) Then
Print "Started execution from file..."
thinBasic_Run(0, sScript, %thinBasic_BufferType_IsFile, 1 Or 2, FALSE, FALSE, FALSE, 1, FALSE)
Else
Print "Started execution from string"
thinBasic_Run(0, FILE_Load(sScript), %thinBasic_BufferType_IsScript, 1 Or 2, FALSE, FALSE, FALSE, 1, FALSE)
End If
PrintL "DONE"
PrintL
Print "Release..."
thinBasic_Release(hScript)
PrintL "DONE"
PrintL
PrintL "Press any key to quit"
WaitKey
End Function
Petr
ReneMiner
20-05-2013, 11:17
I made two files: one is the main file, one symbolizes "the later to load data"
' CallScriptTest.tBasic
' -- Modules
Uses "File", "Console"
' -- ThinCore access
%thinBasic_BufferType_IsFile = 0
%thinBasic_BufferType_IsScript = 1
Dim myScript As Long ' use a GLOBAL for test to stop from external script
Dim foo As String = "Nothing"
Declare Function thinBasic_Init Lib "thinCore.dll" Alias "thinBasic_Init" (ByVal hWnd As Long, ByVal cInstance As Long, ByVal sKey As String) As Long
Declare Function thinBasic_Release Lib "thinCore.dll" Alias "thinBasic_Release" ( ByVal hScript As Long ) As Long
Declare Function thinBasic_Run Lib "thinCore.dll" Alias "thinBasic_Run" (
ByVal hScript As Long ,
ByVal sBuffer As String ,
ByVal BufferType As Long ,
Optional ByVal Options As Long ,
ByVal DebugMode As Long ,
ByVal LogMode As Long ,
ByVal ObfuscateMode As Long ,
ByVal CallingProgram As Long ,
ByVal DependancyMode As Long ) As Long
Function TBMain()
PrintL "foo =" + foo
ExternalScript(APP_ScriptPath + "CallScriptUnit.tBasicU")
PrintL
PrintL "foo =" + foo
PrintL
PrintL "Press any key to quit"
WaitKey
End Function
' ------------------------------------------------------------------------------
Sub ExternalScript(ByVal sFile As String)
PrintL "Sub ExternalScript was called"
If FILE_Exists(sFile) Then
Print "Initializing..."
myScript = thinBasic_Init(0, GetCurrentInstance, "")
PrintL "DONE"
PrintL "Started execution from string"
If thinBasic_Run(myScript, FILE_Load(sFile), %thinBasic_BufferType_IsScript, 1 Or 2, FALSE, FALSE, FALSE, 1, FALSE) Then
' does never get here...
PrintL "Release..."
thinBasic_Release(myScript)
PrintL "DONE"
EndIf
EndIf
End Sub
' the following file next to the main-file
' CallScriptUnit.tBasicU
PrintL "is running"
foo = "Now filled with something"
PrintL "foo =" + foo
foo = "empty again"
PrintL
PrintL "press key to continue..."
WaitKey
' -----------------------------------
Sub ExtTestSub()
PrintL "ExtTestSub was called"
PrintL
PrintL "press key to continue..."
WaitKey
End Sub
ExtTestSub()
PrintL "external script finished"
' thinBasic_Release(0)
' thinBasic_Release(myScript) ' will stop all immediately
' STOP
Problem is- the external script gets executed pretty well - but it does not "come back"