Quelltexte/ Codesnippets | | | | | Von Andreas Miethe: Erklärung dazu. Es werden 2 Datein benötigt, Einmal das eigentliche Programm, zum anderen das was den Loop enthält. Der Loop-Programm muss kompiliert sein. Das Hauptprogramm startet sich einfach selber mit Parametern (Loop-Programm) neu. Das Ganze funktioniert nur wenn beide Programme kompiliert sind !
Ist vielleicht noch verbesserungswürdig, funktioniert aber erstmal !
Loop-Programm ( als timer.prf speichern und kompilieren ) KompilierenMarkierenSeparieren Hauptprogramm KompilierenMarkierenSeparieren#########################################
Thread starten, pausieren lassen, beenden
Andreas Miethe 28.03.2008
#########################################
BEACHTE : starten als EXE oder STRG+F8
#########################################
$IFDEF Compiler
$H Windows.ph
$H Structs.ph
$H Messages.ph
Struct StartupInfo = ~STARTUPINFO
Struct ProcessInfo = ~PROCESS_INFORMATION
Struct MEMORYSTATUS = ~MEMORYSTATUS
Var Ende& = 0
cls ~GetSysColor(~COLOR_BTNFACE)
Declare ProcessHandle&,Processhandle1&
Declare ThreadHandle&,Threadhandle1&
Proc CreateThread
Parameters Param$
Declare StartupInfo#,CommandString$,ProcessInfo#
Declare Retval&,Processhandle&,ThreadHandle&
CommandString$ = Par$(0) + + Param$
Dim StartupInfo#,StartupInfo
Clear StartupInfo#
StartupInfo#.cb& = SizeOf(StartupInfo#)
Dim ProcessInfo#,ProcessInfo
Clear ProcessInfo#
~CreateProcess(0,Addr(CommandString$),0,0,0,0,0,0,StartupInfo#,ProcessInfo#)
ProcessHandle& = ProcessInfo#.hProcess&
ThreadHandle& = ProcessInfo#.hThread&
Dispose StartupInfo#
Dispose ProcessInfo#
Return Str$(ProcessHandle&)+,+Str$(ThreadHandle&)
EndProc
Proc TerminateThread
Parameters ProcessHandle&
Declare ExitCode&
~GetExitCodeProcess(Processhandle&,Addr(ExitCode&))
~TerminateProcess(Processhandle&,ExitCode&)
EndProc
Proc PauseThread
Parameters Threadhandle&
~SuspendThread(Threadhandle&)
EndProc
Proc ResumeThread
Parameters Threadhandle&
~ResumeThread(Threadhandle&)
EndProc
Var Handles$ =
Var Start& = Create(Button,%hwnd,Start,10,10,80,24)
Var Pause& = Create(Button,%hwnd,Pause,10,40,80,24)
Var Resume& = Create(Button,%hwnd,Fortsetzen,10,70,80,24)
Var Terminate& = Create(Button,%hwnd,Ende,10,100,80,24)
Var Empfang& = Create(TEXT,%hwnd,,10,130,80,24)
SendMessage(Start&,~WM_SETFONT,~GetStockObject(~ANSI_VAR_FONT),1)
SendMessage(Pause&,~WM_SETFONT,~GetStockObject(~ANSI_VAR_FONT),1)
SendMessage(Resume&,~WM_SETFONT,~GetStockObject(~ANSI_VAR_FONT),1)
SendMessage(Terminate&,~WM_SETFONT,~GetStockObject(~ANSI_VAR_FONT),1)
SendMessage(Empfang&,~WM_SETFONT,~GetStockObject(~ANSI_VAR_FONT),1)
EnableWindow Pause&,0
EnableWindow Resume&,0
EnableWindow Terminate&,0
Var Statusbar& = Create(StatusWindow,%hwnd,)
UpdateStatus(Statusbar&)
SubClass StatusBar&,1SubClassing einschalten
~SetTimer(StatusBar&,1,1000,0)Timer an die Statusbar hängen
SubClass %hwnd,1SubClassing einschalten
UserMessages ~wm_close
WhileNot Ende&
Waitinput
If Clicked(Start&)
Die Exe startet sich selber noch einmal mit Parametern
der Parameter, der hier erwartet wird ist ein ein Kompilat ( PRC-Datei )
Handles$ = CreateThread(Timer.prc +str$(Empfang&))
ProcessHandle1& = Val(Substr$(Handles$,1,,))
ThreadHandle1& = Val(Substr$(Handles$,2,,))
EnableWindow Pause&,1
EnableWindow Terminate&,1
EnableWindow Start&,0
Elseif Clicked(Pause&)
PauseThread(ThreadHandle1&)
EnableWindow Pause&,0
EnableWindow Resume&,1
ElseIf Clicked(Resume&)
ResumeThread(ThreadHandle1&)
EnableWindow Pause&,1
EnableWindow Resume&,0
ElseIf Clicked(Terminate&)
EnableWindow Pause&,0
EnableWindow Resume&,0
EnableWindow Terminate&,0
EnableWindow Start&,1
TerminateThread(ProcessHandle1&)
Endif
If %Umessage = ~wm_close
wenn TerminateThread() nicht bei Programmende aufgerufen wird,
läuft das 2.Programm weiter !
TerminateThread(ProcessHandle1&)
Ende& = 1
Endif
EndWhile
SubClass StatusBar&,0
SubClass %hwnd,0
end
Proc UpdateStatus
Parameters Statusbar&
Declare MemStatus#
Dim Memstatus#,MEMORYSTATUS
MemStatus#.dwLength& = SizeOf(MemStatus#)
~GlobalMemoryStatus(MemStatus#)
SetText Statusbar&,Jetzt : +Time$(0)+:+Left$(Time$(1),2)+ - Speicherverbrauch : +Str$(MemStatus#.dwMemoryLoad&)+%
Dispose MemStatus#
EndProc
SubClassProc
If SubClassMessage(%hwnd, ~WM_SIZE)
SetWindowPos Statusbar& = 0,0-0,0
ElseIf SubClassMessage(Statusbar&, ~WM_TIMER)
UpdateStatus(&sWnd)
Endif
EndProc
|
| | | | |
| | | Dank gestackter userMessages kann man eine einfache verlustfreie Prozesskommunikation herstellen.
Ein anderes Beispiel könnte dem 2. Prozess das Handle des Hauptfensters als Parameter mit auf dem Weg geben - worüber dann die Messages einfach zu versenden wären. |
| | | | |
| | Andreas Gaida | Hi
oder man verwendet gemeinsame Speicher damit lassen sich schnell und bequem grosse mengen von Daten zwischen mehreren Programmen austauschen oder gemeinsam nutzen.
Habe das Beispiel in der Profan Hilfe gefunden und an meine Bedürfnisse angepast. Bin mir nicht sicher ob ich bei der freigabe des Speichers alles richtig gemacht habe falls nicht wäre ich für eine korrektur dankbar.
Beispiel ( Erst Master Starten dann Slave) : KompilierenMarkierenSeparieren $I mem-create.inc
initialisiert 18 2048 Byte Grosse gemeinsamme Speicher SharedBuffer1# bis SharedBuffer18#
Declare Temp1$,Bereich#,ENDE%
STRUCT shared = variable1%,variable2&,variable3!,variable4$(2033)
Dim Bereich#,shared
Bereich#.variable1% = 32768
Bereich#.variable2& = 2147483647
Bereich#.variable3! = 123.456
Bereich#.variable4$ = und noch ein weiterer test
Window 0,400-500,450
Windowtitle Master
string SharedBuffer1#,0 = das ist ein test
long SharedBuffer2#,0 = 123456789
SharedBuffer3# = Bereich#
Bereich# = SharedBuffer3#
print @String$(SharedBuffer1#,0)
print @long (SharedBuffer2#,0)
print Bereich#.variable1%
print Bereich#.variable2&
print Bereich#.variable3!
print Bereich#.variable4$
settimer 50
WHILENOT ENDE%
WAITINPUT
locate 10,1
clear SharedBuffer3#
Bereich#.variable2& = &GetTickCount
Bereich#.variable4$ = @Time$(0)+:+ @Time$(1)
SharedBuffer3# = Bereich#
ENDWHILE
sharedclear Löscht die Buffer
Dispose Bereich#
KompilierenMarkierenSeparieren $I mem-use.inc
Stellt 18 2048 Byte Grosse gemeinsamme Speicher SharedBuffer1# bis SharedBuffer18#
dem Programm zu verfügung . Müssen aber vorher durch mem-create.inc von einen anderen
Programm erstellt worden sein .
Declare Temp1$,Bereich#,ENDE%
STRUCT shared = variable1%,variable2&,variable3!,variable4$(2033)
Dim Bereich#,shared
Bereich#.variable1% = 32768
Bereich#.variable2& = 2147483647
Bereich#.variable3! = 123.456
Bereich#.variable4$ = und noch ein weiterer test
Window 520,400-500,450
Windowtitle Slave
string SharedBuffer1#,0 = das ist ein test
long SharedBuffer2#,0 = 123456789
SharedBuffer3# = Bereich#
Bereich# = SharedBuffer3#
print @String$(SharedBuffer1#,0)
print @long (SharedBuffer2#,0)
print Bereich#.variable1%
print Bereich#.variable2&
print Bereich#.variable3!
print Bereich#.variable4$
settimer 50
WHILENOT ENDE%
WAITINPUT
locate 10,1
print
print
locate 10,1
Bereich# = SharedBuffer3#
print Bereich#.variable2&
print Bereich#.variable4$
ENDWHILE
KompilierenMarkierenSeparierenmem-create.inc
$H Windows.ph
Def &MapFileSize1 2048
Def &MapFileSize2 2048
Def &MapFileSize3 2048
Def &MapFileSize4 2048
Def &MapFileSize5 2048
Def &MapFileSize6 2048
Def &MapFileSize7 2048
Def &MapFileSize8 2048
Def &MapFileSize9 2048
Def &MapFileSize10 2048
Def &MapFileSize11 2048
Def &MapFileSize12 2048
Def &MapFileSize13 2048
Def &MapFileSize14 2048
Def &MapFileSize15 2048
Def &MapFileSize16 2048
Def &MapFileSize17 2048
Def &MapFileSize18 2048
Declare hFileMap1&
Declare hFileMap2&
Declare hFileMap3&
Declare hFileMap4&
Declare hFileMap5&
Declare hFileMap6&
Declare hFileMap7&
Declare hFileMap8&
Declare hFileMap9&
Declare hFileMap10&
Declare hFileMap11&
Declare hFileMap12&
Declare hFileMap13&
Declare hFileMap14&
Declare hFileMap15&
Declare hFileMap16&
Declare hFileMap17&
Declare hFileMap18&
Declare FileMapName1$
Declare FileMapName2$
Declare FileMapName3$
Declare FileMapName4$
Declare FileMapName5$
Declare FileMapName6$
Declare FileMapName7$
Declare FileMapName8$
Declare FileMapName9$
Declare FileMapName10$
Declare FileMapName11$
Declare FileMapName12$
Declare FileMapName13$
Declare FileMapName14$
Declare FileMapName15$
Declare FileMapName16$
Declare FileMapName17$
Declare FileMapName18$
Declare SharedBuffer1#, BufferAddr1& ,b& ,c&
Declare SharedBuffer2#, BufferAddr2&
Declare SharedBuffer3#, BufferAddr3&
Declare SharedBuffer4#, BufferAddr4&
Declare SharedBuffer5#, BufferAddr5&
Declare SharedBuffer6#, BufferAddr6&
Declare SharedBuffer7#, BufferAddr7&
Declare SharedBuffer8#, BufferAddr8&
Declare SharedBuffer9#, BufferAddr9&
Declare SharedBuffer10#, BufferAddr10&
Declare SharedBuffer11#, BufferAddr11&
Declare SharedBuffer12#, BufferAddr12&
Declare SharedBuffer13#, BufferAddr13&
Declare SharedBuffer14#, BufferAddr14&
Declare SharedBuffer15#, BufferAddr15&
Declare SharedBuffer16#, BufferAddr16&
Declare SharedBuffer17#, BufferAddr17&
Declare SharedBuffer18#, BufferAddr18&
Dim SharedBuffer1#, 2048
Dim SharedBuffer2#, 2048
Dim SharedBuffer3#, 2048
Dim SharedBuffer4#, 2048
Dim SharedBuffer5#, 2048
Dim SharedBuffer6#, 2048
Dim SharedBuffer7#, 2048
Dim SharedBuffer8#, 2048
Dim SharedBuffer9#, 2048
Dim SharedBuffer10#, 2048
Dim SharedBuffer11#, 2048
Dim SharedBuffer12#, 2048
Dim SharedBuffer13#, 2048
Dim SharedBuffer14#, 2048
Dim SharedBuffer15#, 2048
Dim SharedBuffer16#, 2048
Dim SharedBuffer17#, 2048
Dim SharedBuffer18#, 2048
BufferAddr1& = SharedBuffer1#
BufferAddr2& = SharedBuffer2#
BufferAddr3& = SharedBuffer3#
BufferAddr4& = SharedBuffer4#
BufferAddr5& = SharedBuffer5#
BufferAddr6& = SharedBuffer6#
BufferAddr7& = SharedBuffer7#
BufferAddr8& = SharedBuffer8#
BufferAddr9& = SharedBuffer9#
BufferAddr10& = SharedBuffer10#
BufferAddr11& = SharedBuffer11#
BufferAddr12& = SharedBuffer12#
BufferAddr13& = SharedBuffer13#
BufferAddr14& = SharedBuffer14#
BufferAddr15& = SharedBuffer15#
BufferAddr16& = SharedBuffer16#
BufferAddr17& = SharedBuffer17#
BufferAddr18& = SharedBuffer18#
FileMapName1$ = sharedmap1 + @Chr$(0)
FileMapName2$ = sharedmap2 + @Chr$(0)
FileMapName3$ = sharedmap3 + @Chr$(0)
FileMapName4$ = sharedmap4 + @Chr$(0)
FileMapName5$ = sharedmap5 + @Chr$(0)
FileMapName6$ = sharedmap6 + @Chr$(0)
FileMapName7$ = sharedmap7 + @Chr$(0)
FileMapName8$ = sharedmap8 + @Chr$(0)
FileMapName9$ = sharedmap9 + @Chr$(0)
FileMapName10$ = sharedmap10 + @Chr$(0)
FileMapName11$ = sharedmap11 + @Chr$(0)
FileMapName12$ = sharedmap12 + @Chr$(0)
FileMapName13$ = sharedmap13 + @Chr$(0)
FileMapName14$ = sharedmap14 + @Chr$(0)
FileMapName15$ = sharedmap15 + @Chr$(0)
FileMapName16$ = sharedmap16 + @Chr$(0)
FileMapName17$ = sharedmap17 + @Chr$(0)
FileMapName18$ = sharedmap18 + @Chr$(0)
hFileMap1& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize1, @Addr(FileMapName1$))
hFileMap2& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize2, @Addr(FileMapName2$))
hFileMap3& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize3, @Addr(FileMapName3$))
hFileMap4& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize4, @Addr(FileMapName4$))
hFileMap5& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize5, @Addr(FileMapName5$))
hFileMap6& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize6, @Addr(FileMapName6$))
hFileMap7& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize7, @Addr(FileMapName7$))
hFileMap8& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize8, @Addr(FileMapName8$))
hFileMap9& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize9, @Addr(FileMapName9$))
hFileMap10& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize10, @Addr(FileMapName10$))
hFileMap11& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize11, @Addr(FileMapName11$))
hFileMap12& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize12, @Addr(FileMapName12$))
hFileMap13& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize13, @Addr(FileMapName13$))
hFileMap14& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize14, @Addr(FileMapName14$))
hFileMap15& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize15, @Addr(FileMapName15$))
hFileMap16& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize16, @Addr(FileMapName16$))
hFileMap17& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize17, @Addr(FileMapName17$))
hFileMap18& = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,&MapFileSize18, @Addr(FileMapName18$))
hFileMap1& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName1$))
hFileMap2& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName2$))
hFileMap3& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName3$))
hFileMap4& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName4$))
hFileMap5& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName5$))
hFileMap6& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName6$))
hFileMap7& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName7$))
hFileMap8& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName8$))
hFileMap9& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName9$))
hFileMap10& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName10$))
hFileMap11& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName11$))
hFileMap12& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName12$))
hFileMap13& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName13$))
hFileMap14& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName14$))
hFileMap15& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName15$))
hFileMap16& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName16$))
hFileMap17& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName17$))
hFileMap18& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName18$))
SharedBuffer1# = ~MapViewOfFile(hFileMap1&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer2# = ~MapViewOfFile(hFileMap2&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer3# = ~MapViewOfFile(hFileMap3&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer4# = ~MapViewOfFile(hFileMap4&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer5# = ~MapViewOfFile(hFileMap5&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer6# = ~MapViewOfFile(hFileMap6&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer7# = ~MapViewOfFile(hFileMap7&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer8# = ~MapViewOfFile(hFileMap8&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer9# = ~MapViewOfFile(hFileMap9&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer10# = ~MapViewOfFile(hFileMap10&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer11# = ~MapViewOfFile(hFileMap11&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer12# = ~MapViewOfFile(hFileMap12&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer13# = ~MapViewOfFile(hFileMap13&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer14# = ~MapViewOfFile(hFileMap14&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer15# = ~MapViewOfFile(hFileMap15&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer16# = ~MapViewOfFile(hFileMap16&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer17# = ~MapViewOfFile(hFileMap17&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer18# = ~MapViewOfFile(hFileMap18&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
PROC sharedclear
SharedBuffer1# = BufferAddr1&
SharedBuffer2# = BufferAddr2&
SharedBuffer3# = BufferAddr3&
SharedBuffer4# = BufferAddr4&
SharedBuffer5# = BufferAddr5&
SharedBuffer6# = BufferAddr6&
SharedBuffer7# = BufferAddr7&
SharedBuffer8# = BufferAddr8&
SharedBuffer9# = BufferAddr9&
SharedBuffer10# = BufferAddr10&
SharedBuffer11# = BufferAddr11&
SharedBuffer12# = BufferAddr12&
SharedBuffer13# = BufferAddr13&
SharedBuffer14# = BufferAddr14&
SharedBuffer15# = BufferAddr15&
SharedBuffer16# = BufferAddr16&
SharedBuffer17# = BufferAddr17&
SharedBuffer18# = BufferAddr18&
Dispose SharedBuffer1#
Dispose SharedBuffer2#
Dispose SharedBuffer3#
Dispose SharedBuffer4#
Dispose SharedBuffer5#
Dispose SharedBuffer6#
Dispose SharedBuffer7#
Dispose SharedBuffer8#
Dispose SharedBuffer9#
Dispose SharedBuffer10#
Dispose SharedBuffer11#
Dispose SharedBuffer12#
Dispose SharedBuffer13#
Dispose SharedBuffer14#
Dispose SharedBuffer15#
Dispose SharedBuffer16#
Dispose SharedBuffer17#
Dispose SharedBuffer18#
ENDPROC
KompilierenMarkierenSeparierenmem-use.inc
$H Windows.ph
Def &MapFileSize1 2048
Def &MapFileSize2 2048
Def &MapFileSize3 2048
Def &MapFileSize4 2048
Def &MapFileSize5 2048
Def &MapFileSize6 2048
Def &MapFileSize7 2048
Def &MapFileSize8 2048
Def &MapFileSize9 2048
Def &MapFileSize10 2048
Def &MapFileSize11 2048
Def &MapFileSize12 2048
Def &MapFileSize13 2048
Def &MapFileSize14 2048
Def &MapFileSize15 2048
Def &MapFileSize16 2048
Def &MapFileSize17 2048
Def &MapFileSize18 2048
Declare hFileMap1&
Declare hFileMap2&
Declare hFileMap3&
Declare hFileMap4&
Declare hFileMap5&
Declare hFileMap6&
Declare hFileMap7&
Declare hFileMap8&
Declare hFileMap9&
Declare hFileMap10&
Declare hFileMap11&
Declare hFileMap12&
Declare hFileMap13&
Declare hFileMap14&
Declare hFileMap15&
Declare hFileMap16&
Declare hFileMap17&
Declare hFileMap18&
Declare FileMapName1$
Declare FileMapName2$
Declare FileMapName3$
Declare FileMapName4$
Declare FileMapName5$
Declare FileMapName6$
Declare FileMapName7$
Declare FileMapName8$
Declare FileMapName9$
Declare FileMapName10$
Declare FileMapName11$
Declare FileMapName12$
Declare FileMapName13$
Declare FileMapName14$
Declare FileMapName15$
Declare FileMapName16$
Declare FileMapName17$
Declare FileMapName18$
Declare SharedBuffer1#, BufferAddr1& ,b& ,c&
Declare SharedBuffer2#, BufferAddr2&
Declare SharedBuffer3#, BufferAddr3&
Declare SharedBuffer4#, BufferAddr4&
Declare SharedBuffer5#, BufferAddr5&
Declare SharedBuffer6#, BufferAddr6&
Declare SharedBuffer7#, BufferAddr7&
Declare SharedBuffer8#, BufferAddr8&
Declare SharedBuffer9#, BufferAddr9&
Declare SharedBuffer10#, BufferAddr10&
Declare SharedBuffer11#, BufferAddr11&
Declare SharedBuffer12#, BufferAddr12&
Declare SharedBuffer13#, BufferAddr13&
Declare SharedBuffer14#, BufferAddr14&
Declare SharedBuffer15#, BufferAddr15&
Declare SharedBuffer16#, BufferAddr16&
Declare SharedBuffer17#, BufferAddr17&
Declare SharedBuffer18#, BufferAddr18&
Dim SharedBuffer1#, 2048
Dim SharedBuffer2#, 2048
Dim SharedBuffer3#, 2048
Dim SharedBuffer4#, 2048
Dim SharedBuffer5#, 2048
Dim SharedBuffer6#, 2048
Dim SharedBuffer7#, 2048
Dim SharedBuffer8#, 2048
Dim SharedBuffer9#, 2048
Dim SharedBuffer10#, 2048
Dim SharedBuffer11#, 2048
Dim SharedBuffer12#, 2048
Dim SharedBuffer13#, 2048
Dim SharedBuffer14#, 2048
Dim SharedBuffer15#, 2048
Dim SharedBuffer16#, 2048
Dim SharedBuffer17#, 2048
Dim SharedBuffer18#, 2048
BufferAddr1& = SharedBuffer1#
BufferAddr2& = SharedBuffer2#
BufferAddr3& = SharedBuffer3#
BufferAddr4& = SharedBuffer4#
BufferAddr5& = SharedBuffer5#
BufferAddr6& = SharedBuffer6#
BufferAddr7& = SharedBuffer7#
BufferAddr8& = SharedBuffer8#
BufferAddr9& = SharedBuffer9#
BufferAddr10& = SharedBuffer10#
BufferAddr11& = SharedBuffer11#
BufferAddr12& = SharedBuffer12#
BufferAddr13& = SharedBuffer13#
BufferAddr14& = SharedBuffer14#
BufferAddr15& = SharedBuffer15#
BufferAddr16& = SharedBuffer16#
BufferAddr17& = SharedBuffer17#
BufferAddr18& = SharedBuffer18#
FileMapName1$ = sharedmap1 + @Chr$(0)
FileMapName2$ = sharedmap2 + @Chr$(0)
FileMapName3$ = sharedmap3 + @Chr$(0)
FileMapName4$ = sharedmap4 + @Chr$(0)
FileMapName5$ = sharedmap5 + @Chr$(0)
FileMapName6$ = sharedmap6 + @Chr$(0)
FileMapName7$ = sharedmap7 + @Chr$(0)
FileMapName8$ = sharedmap8 + @Chr$(0)
FileMapName9$ = sharedmap9 + @Chr$(0)
FileMapName10$ = sharedmap10 + @Chr$(0)
FileMapName11$ = sharedmap11 + @Chr$(0)
FileMapName12$ = sharedmap12 + @Chr$(0)
FileMapName13$ = sharedmap13 + @Chr$(0)
FileMapName14$ = sharedmap14 + @Chr$(0)
FileMapName15$ = sharedmap15 + @Chr$(0)
FileMapName16$ = sharedmap16 + @Chr$(0)
FileMapName17$ = sharedmap17 + @Chr$(0)
FileMapName18$ = sharedmap18 + @Chr$(0)
hFileMap1& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName1$))
hFileMap2& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName2$))
hFileMap3& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName3$))
hFileMap4& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName4$))
hFileMap5& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName5$))
hFileMap6& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName6$))
hFileMap7& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName7$))
hFileMap8& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName8$))
hFileMap9& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName9$))
hFileMap10& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName10$))
hFileMap11& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName11$))
hFileMap12& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName12$))
hFileMap13& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName13$))
hFileMap14& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName14$))
hFileMap15& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName15$))
hFileMap16& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName16$))
hFileMap17& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName17$))
hFileMap18& = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName18$))
SharedBuffer1# = ~MapViewOfFile(hFileMap1&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer2# = ~MapViewOfFile(hFileMap2&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer3# = ~MapViewOfFile(hFileMap3&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer4# = ~MapViewOfFile(hFileMap4&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer5# = ~MapViewOfFile(hFileMap5&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer6# = ~MapViewOfFile(hFileMap6&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer7# = ~MapViewOfFile(hFileMap7&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer8# = ~MapViewOfFile(hFileMap8&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer9# = ~MapViewOfFile(hFileMap9&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer10# = ~MapViewOfFile(hFileMap10&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer11# = ~MapViewOfFile(hFileMap11&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer12# = ~MapViewOfFile(hFileMap12&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer13# = ~MapViewOfFile(hFileMap13&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer14# = ~MapViewOfFile(hFileMap14&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer15# = ~MapViewOfFile(hFileMap15&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer16# = ~MapViewOfFile(hFileMap16&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer17# = ~MapViewOfFile(hFileMap17&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
SharedBuffer18# = ~MapViewOfFile(hFileMap18&, ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
PROC sharedclear
SharedBuffer1# = BufferAddr1&
SharedBuffer2# = BufferAddr2&
SharedBuffer3# = BufferAddr3&
SharedBuffer4# = BufferAddr4&
SharedBuffer5# = BufferAddr5&
SharedBuffer6# = BufferAddr6&
SharedBuffer7# = BufferAddr7&
SharedBuffer8# = BufferAddr8&
SharedBuffer9# = BufferAddr9&
SharedBuffer10# = BufferAddr10&
SharedBuffer11# = BufferAddr11&
SharedBuffer12# = BufferAddr12&
SharedBuffer13# = BufferAddr13&
SharedBuffer14# = BufferAddr14&
SharedBuffer15# = BufferAddr15&
SharedBuffer16# = BufferAddr16&
SharedBuffer17# = BufferAddr17&
SharedBuffer18# = BufferAddr18&
Dispose SharedBuffer1#
Dispose SharedBuffer2#
Dispose SharedBuffer3#
Dispose SharedBuffer4#
Dispose SharedBuffer5#
Dispose SharedBuffer6#
Dispose SharedBuffer7#
Dispose SharedBuffer8#
Dispose SharedBuffer9#
Dispose SharedBuffer10#
Dispose SharedBuffer11#
Dispose SharedBuffer12#
Dispose SharedBuffer13#
Dispose SharedBuffer14#
Dispose SharedBuffer15#
Dispose SharedBuffer16#
Dispose SharedBuffer17#
Dispose SharedBuffer18#
ENDPROC
MfG Andreas |
| | | Athlon X2 4800 , 2GB Ram , GeForce 7800GT Windows XP Pro , XProfan 10 und 11 , Profan2Cpp 1.6b | 29.03.2008 ▲ |
| |
| | | Andreas Gaida
Hi
oder man verwendet gemeinsame Speicher damit lassen sich schnell und bequem grosse mengen von Daten zwischen mehreren Programmen austauschen oder gemeinsam nutzen
...
MfG Andreas
Jupp, und das wiederum vereinfacht die pipe.unit erheblich. [...]
PS: Nutze doch Arrays - die machen den Code kompakter. |
| | | | |
| | Andreas Gaida | Wie meins Du das mit dem Arrays? Kannst Du vielleicht ein kleines Beispiel dafür liefern um mir auf die sprünge zu helfen?
MfG Andreas |
| | | Athlon X2 4800 , 2GB Ram , GeForce 7800GT Windows XP Pro , XProfan 10 und 11 , Profan2Cpp 1.6b | 29.03.2008 ▲ |
| |
| | Jörg Sellmeyer | Etwa so: KompilierenMarkierenSeparieren Das müßte mit den Strings auch so funktionieren und erspart Dir die ganzen Deklarationen und Du kannst die Arrays in einer Schleife befüllen. |
| | | Windows XP SP2 XProfan X4... und hier mal was ganz anderes als Profan ... | 29.03.2008 ▲ |
| |
| | Andreas Gaida | | | | Athlon X2 4800 , 2GB Ram , GeForce 7800GT Windows XP Pro , XProfan 10 und 11 , Profan2Cpp 1.6b | 29.03.2008 ▲ |
| |
| | Andreas Gaida | Dank der Inspiration von If und des Denk Anstosses von Jörg Sellmeyer hier nun die Extrem verkürzte Version mit bis zu 100 Shared Buffers
Habe SharedBuffer# in S_Bereich# umbenannt bitte die neuen Beispiele mit der Inc verwenden. KompilierenMarkierenSeparieren $I mem-create-use.inc
Declare Temp1$,Bereich#,ENDE%
STRUCT shared = variable1%,variable2&,variable3!,variable4$(2033)
Dim Bereich#,shared
Init_Shared 2048,50,MASTER Initialisiert den Shared Buffer
Bereich#.variable1% = 32768
Bereich#.variable2& = 2147483647
Bereich#.variable3! = 123.456
Bereich#.variable4$ = und noch ein weiterer test
Window 0,400-500,450
Windowtitle Master
string S_Bereich#[1],0 = das ist ein test
long S_Bereich#[2],0 = 123456789
S_Bereich#[3] = Bereich#
Bereich# = S_Bereich#[3]
print @String$(S_Bereich#[1],0)
print @long (S_Bereich#[2],0)
print Bereich#.variable1%
print Bereich#.variable2&
print Bereich#.variable3!
print Bereich#.variable4$
settimer 250
WHILENOT ENDE%
WAITINPUT
locate 10,1
clear S_Bereich#[3]
clear S_Bereich#[4]
Bereich#.variable2& = &GetTickCount
Bereich#.variable4$ = @Time$(0)+:+ @Time$(1)
S_Bereich#[3] = Bereich#
Bereich#.variable2& = 1234567890
Bereich#.variable4$ = qwertzuiopüasdfghjkl
S_Bereich#[4] = Bereich#
ENDWHILE
Clear_Shared 50 Löscht die angegebene anzahl von Buffern
Dispose Bereich#
KompilierenMarkierenSeparieren $I mem-create-use.inc
Declare Temp1$,Bereich#,ENDE%
Init_Shared 2048,50,SLAVE
STRUCT shared = variable1%,variable2&,variable3!,variable4$(2033)
Dim Bereich#,shared
Window 520,400-500,450
Windowtitle Slave
settimer 50
WHILENOT ENDE%
WAITINPUT
locate 10,1
print
print
locate 10,1
Bereich# = S_Bereich#[3]
print Bereich#.variable2&
print Bereich#.variable4$
Bereich# = S_Bereich#[4]
print Bereich#.variable2&
print Bereich#.variable4$
ENDWHILE
KompilierenMarkierenSeparierenmem-create-use.inc
$H Windows.ph
Declare FileMapName$[100],BufferAddr&[100],hFileMap&[100],S_Bereich#[100],MapFileSize&[100]
proc Init_Shared
Parameters groesse&,anzahl&,modus$ Grösse des Buffers, Anzahl der Buffer, Modus
Dim S_Bereich#[],2048
WhileLoop anzahl&
MapFileSize&[&Loop] = groesse&
EndWhile
WhileLoop anzahl&
BufferAddr&[&Loop] = S_Bereich#[&Loop]
EndWhile
WhileLoop anzahl&
FileMapName$[&Loop] = sharedmap + STR$(&Loop) + @Chr$(0)
EndWhile
If modus$ = MASTER bei MASTER wird der Speicher nur erstellt
WhileLoop anzahl&
hFileMap&[&Loop] = ~CreateFileMapping($FFFFFFFF, 0, ~PAGE_READWRITE, 0,MapFileSize&[&Loop], @Addr(FileMapName$[&Loop]))
EndWhile
Elseif modus$ = SLAVE
Endif
WhileLoop anzahl&
hFileMap&[&Loop] = ~OpenFileMapping(~FILE_MAP_ALL_ACCESS, 0, @Addr(FileMapName$[&Loop]))
EndWhile
WhileLoop anzahl&
S_Bereich#[&Loop] = ~MapViewOfFile(hFileMap&[&Loop], ~FILE_MAP_ALL_ACCESS, 0, 0, 0)
EndWhile
Endproc
PROC Clear_Shared
Parameters anzahl&
WhileLoop anzahl&
S_Bereich#[&Loop] = BufferAddr&[&Loop]
EndWhile
Dispose S_Bereich#[]
ENDPROC
|
| | | Athlon X2 4800 , 2GB Ram , GeForce 7800GT Windows XP Pro , XProfan 10 und 11 , Profan2Cpp 1.6b | 29.03.2008 ▲ |
| |
|
Zum QuelltextThemenoptionen | 4.193 Betrachtungen |
ThemeninformationenDieses Thema hat 3 Teilnehmer: |