So...nachdem ich mich nun lange mit irgendwelchen Bugs beim DLL-Call (Speicherfehler) und mit RunProgramm (Parameter wurden nicht durchgereicht - beides untersuche ich noch weiter...in den kleinen Beispielen die ich euch posten wollte, geht es nämlich...) verbracht habe...
Hier eine (noch etwas schäbige) Lösung für sowas wie "Live code"... mit compile-batch-skript und erstmal auf Konsole.
Ist beides sicherlich nicht der große Wurf, aber man bekommt eine Idee davon. Wenn die andern Probleme gelöst sind, dann lässt es sich auch von der Performance noch deutlich optimieren - allein schon wegen der Synchronisation, wann die DLL gerade locked ist, aber auch weil man dann nur noch recompiled, wenn der Source verändert wurde...
recompileDLL.bat
Code: Alles auswählen
@echo off
:compile
"%ProgramFiles%\PureBasic\Compilers\pbcompiler.exe" test.pb /EXE test.dll /DLL
timeout 1
goto compile
ContainerApp.pb (die Exe sollte im gleichen Ordner liegen wie die DLL)
Code: Alles auswählen
;Global *MemoryAdr = AllocateMemory(5000) ;just for testing
;-----------------------------------
Structure StructuredMemoryType
;control area
SignalToDLL.i
SignalFromDLL.i
;user data
DataContainer.i[1000]
EndStructure
;Static *GlobalStructure.StructuredMemoryType
Global *GlobalStructure.StructuredMemoryType
*GlobalStructure = AllocateStructure(StructuredMemoryType) ; oder *GlobalStructure = AllocateMemory(SizeOf(StructuredMemoryType))
;------------------------------------
*GlobalStructure\SignalToDLL = 55
*GlobalStructure\Datacontainer[0] = 25 ;just for testing
*GlobalStructure\Datacontainer[999] = 42 ;just for testing
If OpenConsole("Live Coding and Loading") And (*GlobalStructure <> 0)
EnableGraphicalConsole(1)
Repeat
ClearConsole()
If OpenLibrary(0, "test.dll") <> 0
CallFunction(0,"Experiment",*GlobalStructure)
CloseLibrary(0)
Delay(100) ;temporary here because of blocked file-handle
Else
ConsoleLocate(1, 24)
Print("DLL could not be loaded")
EndIf
Debug("execution time of pure user code: " + Str(*GlobalStructure\SignalFromDLL) + "ms")
Until Inkey() = Chr(27); Esc
FreeStructure(*GlobalStructure)
Else
MessageRequester("Error", "Can't open Console or can't allocate Memory", #PB_MessageRequester_Ok | #PB_MessageRequester_Error)
End
EndIf
End
; IDE Options = PureBasic 5.71 LTS (Windows - x64)
; CompileSourceDirectory
test.pb (test.dll - da wird Live dran gearbeitet - momentan noch ohne jegliches ErrorHandling. Falls jemand weiß, wie man die etwas sperrigen Struct-Bezeichner auf kleine innere Variablen umbiegt (den Pointer darauf kopiert, siehe comments im Code), dann bin ich sehr dankbar)
Code: Alles auswählen
Structure StructuredMemoryType
;control area
SignalToDLL.i
SignalFromDLL.i
;user data
DataContainer.i[1000]
EndStructure
ProcedureDLL Experiment(*GlobalStructure)
StartTime.q = ElapsedMilliseconds()
*myMemory.StructuredMemoryType
*myMemory = *GlobalStructure
If OpenConsole("Live Coding and Loading")
EnableGraphicalConsole(1)
;user code----------
; x.i
; y.i
; *x = @*myMemory\DataContainer[1]
; *y = @*myMemory\DataContainer[2]
;Speed/Direction init
If *myMemory\DataContainer[3] = 0
;seems to be the first start -> init speed and start position
*myMemory\DataContainer[3] = 1
*myMemory\DataContainer[4] = 1
*myMemory\DataContainer[1] = 5
*myMemory\DataContainer[2] = 5
EndIf
;Direction changing
If (*myMemory\DataContainer[1] > 40) Or (*myMemory\DataContainer[1] < 2)
*myMemory\DataContainer[3] = -*myMemory\DataContainer[3]
EndIf
If (*myMemory\DataContainer[2] > 25) Or (*myMemory\DataContainer[2] < 2)
*myMemory\DataContainer[4] = -*myMemory\DataContainer[4]
EndIf
;Set new position
*myMemory\DataContainer[1] = *myMemory\DataContainer[1] + *myMemory\DataContainer[3] ;yep, thers a shorter way to write...
*myMemory\DataContainer[2] = *myMemory\DataContainer[2] + *myMemory\DataContainer[4]
;print position
ConsoleLocate(0, 0)
Print("("+Str(*myMemory\DataContainer[1])+","+Str(*myMemory\DataContainer[2])+")")
;print 'ball'
ConsoleLocate(*myMemory\DataContainer[1], *myMemory\DataContainer[2])
Print("*")
;user code----------
*myMemory\SignalFromDLL = ElapsedMilliseconds() - StartTime
;Debug(x)
;Debug(y)
;CallDebugger
ConsoleLocate(0, 24)
Print("press esc to close")
;Delay(100)
EndIf
EndProcedure
; IDE Options = PureBasic 5.71 LTS (Windows - x64)
; CompileSourceDirectory
Falls sich jemand an der Bugsuche beteiligen möchte, so sind hier 2 weitere Codes:
Snippet zum Recompile:
Code: Alles auswählen
Procedure ReCompile()
;CompilerPath$ = #PB_Compiler_Home+"/Compilers/pbcompiler.exe"
CompilerPath$ = GetPathPart(ProgramFilename())+"parameterChecker.exe"
SourcePath$ = GetPathPart(ProgramFilename())+"test.pb"
DLLPath$ = GetPathPart(ProgramFilename())+"test.dll"
;/EXE = "output"
; -> pbcompiler source.pb /EXE test.dll /DLL
CompilerParamLine$ = ~"\"" + SourcePath$ + ~"\"" + "/EXE" + ~"\"" + DLLPath$ + ~"\"" + " /DLL"
;CompilerParamLine$ = "/DLL test.pb"
Compiler = RunProgram(CompilerPath$, CompilerCmdLine$, GetPathPart(ProgramFilename()) ,#PB_Program_Open); | #PB_Program_Read)
Output$ = ""
If Compiler <> 0
;WaitProgram(Compiler,10000)
While ProgramRunning(Compiler) <> 0
If AvailableProgramOutput(Compiler)
Output$ + ReadProgramString(Compiler) + Chr(13)
EndIf
Wend
Output$ + Chr(13) + Chr(13)
Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))
Debug(Output$)
CloseProgram(Compiler) ; Schließt die Verbindung zum Programm
Else
Debug("Error RunRpogram")
EndIf
ProcedureReturn 0
EndProcedure
Der parameterChecker der im Code aufgerufen wird ist hier und gibt einfach nur die empfangenen Parameter aus:
Code: Alles auswählen
;ParamChecker for RunProgram-Debugging...
OpenConsole()
NumberOfParameters = CountProgramParameters()
PrintN("Parameter-Checker")
PrintN("---------------------------------")
PrintN("Program was started with " + Str(NumberOfParameters) + " parameters:")
For i=1 To NumberOfParameters
PrintN(ProgramParameter())
Next i
PrintN("")
PrintN("Enter Exitcode or press Enter to close")
ExitStr$ = Input()
ExitCode = 0
If ExitStr$ <> ""
ExitCode=Int(Val(ExitStr$))
EndIf
PrintN("Exiting with Code " + Str(ExitCode))
End ExitCode
; IDE Options = PureBasic 5.71 LTS (Windows - x64)
; CursorPosition = 9
; EnableXP
; Executable = parameterChecker.exe
; CompileSourceDirectory
Es ist auch noch etwas da fürs OnError Errorhandling, das war aber auch mehr ein dirty hack und macht den Code nur unsauberer, darum ist der Fokus erst einmal auf die andern Fehler.