Source / code snippets | | | | R.Schneider | Hello
two programs swap data by WM_COPYDATA from. simply one Program create and then, around the second Program to create, The three marked Lines in the View source by the auskommentierten Lines supplant. The Text in the Edit appear to pressing the send-Buttons in the Edit the others Program. ex Profan 8 because of ProcAddr()
Perhaps can it Yes someone need.
Def CopyMemory(3) !KERNEL32,RtlMoveMemory
$H Structs.ph
$H Messages.ph
$H windows.ph
Declare end%, SendeBtn&, EndeBtn&, Edit&
Declare Groesse&, Text$, ProgHndl&, AltProc&
Declare CopyData#, EigeneDaten#
Struct SCopyData = ~COPYDATASTRUCT
Dim CopyData#, SCopyData
Window Style 538
Window Title Program1//> for Program 2 these Lines Remove
Window Int(%MaxX / 2 - 200),Int(%MaxY / 2 - 100)-195,100//>
Window Title Program2//< and these Lines insert
Window Int(%MaxX / 2 + 5),Int(%MaxY / 2 - 100)-195,100
Set(FastMode,1)
EndeBtn& = Create(Button,%hWnd,terminate,105,50,70,20)
SendeBtn& = Create(Button,%hWnd,Send,15,50,70,20)
Edit& = Create(Edit, %hWnd, , 10, 15, 170, 24)
Proc Send
Parameters Message$
With CopyData#
.dwData& = 0
.cbData& = SizeOf(Message$)
.lpData& = Addr(Message$)
EndWith
Sendmessage(ProgHndl&,~WM_COPYDATA,%hWnd,Addr(CopyData#))
ENDPROC
Proc WndProc
parameters wnd&, msg&, wparam&, lparam&
If msg&=~WM_COPYDATA
CopyMemory(CopyData#,lparam&,12)
Groesse& = CopyData#.cbData&
Dim EigeneDaten#, Groesse&
CopyMemory(EigeneDaten#,CopyData#.lpData&,Groesse&)
Text$ = String $(EigeneDaten#,0)
Dispose EigeneDaten#
EndIf
return call(AltProc&,wnd&,msg&,wparam&,lparam&)
Endproc
AltProc&=~SetWindowLong(%hwnd,~GWL_WNDPROC,ProcAddr(WndProc,4))
While 1
ProgHndl&=FindWindow(Program2)//> for Program 2 these row Remove
ProgHndl&=FindWindow(Program1)//< and these row insert
Case ProgHndl&: Break
Sleep 100
EndWhile
User Messages ~WM_COPYDATA
WhileNot end%
WaitInput
If %Key = 2
Let end% = 1
ElseIf GetFocus(EndeBtn&)
Let end% = 1
ElseIf GetFocus(SendeBtn&)
Send GetText$(Edit&)
ElseIf %umessage=~WM_COPYDATA
SetText Edit&, Text$
Endif
EndWhile
Dispose CopyData#
End
Rudger |
| | | | |
| | p.specht
| straight successful ausprobiert with the nachfolgenden both Programs (INCLUDE-way adjust!). but: at that Send the Message "test" etc. works everything. at that Send of "testikel" on PROGRAMM2 comes but "testikelG" on. What do I do wrong?
PROGRAMM1:
'INTER-PROGRAMM KOMMUNIKATION
'by Rudger tailor, 06.04.2007
'two programs swap data by WM_COPYDATA from. simply one Program create and then,
'around the second Program to create, The three marked Lines in the View source by the
'auskommentierten Lines supplant. The Text in the Edit appear to pressing the send-Buttons
'in the Edit the others Program. ex Profan 8 because of ProcAddr()
'"Vielleicht can it Yes someone brauchen".
'((Vkejjb))-Grant by Rudger tailor, 06.04.2007 on XProfan.net
Def CopyMemory(3) !"KERNEL32","RtlMoveMemory"
$H C:\Program Files (x86)\XProfan11\INCLUDE\Structs.ph
$H C:\Program Files (x86)\XProfan11\INCLUDE\Messages.ph
$H C:\Program Files (x86)\XProfan11\INCLUDE\windows.ph
Declare end%, SendeBtn&, EndeBtn&, Edit&
Declare Groesse&, Text$, ProgHndl&, AltProc&
Declare CopyData#, EigeneDaten#
Struct SCopyData = ~COPYDATASTRUCT
Dim CopyData#, SCopyData
Window Style 538
Window Title "PROGRAMM1"//> for Program 2 these Lines Remove
Window Int(%MaxX / 2 - 200),Int(%MaxY / 2 - 100)-195,100//>
'Window Title "PROGRAMM2" //< and these Lines insert
'Window Int(%MaxX / 2 + 5),Int(%MaxY / 2 - 100)-195,100
Set("FastMode",1)
EndeBtn& = Create("Button",%hWnd,"Beenden",105,50,70,20)
SendeBtn& = Create("Button",%hWnd,"Senden",15,50,70,20)
Edit& = Create("Edit", %hWnd,"", 10, 15, 170, 24)
Proc Send
Parameters Message$
With CopyData#
.dwData& = 0
.cbData& = SizeOf(Message$)
.lpData& = Addr(Message$)
EndWith
Sendmessage(ProgHndl&,~WM_COPYDATA,%hWnd,Addr(CopyData#))
ENDPROC
Proc WndProc
parameters wnd&, msg&, wparam&, lparam&
If msg&=~WM_COPYDATA
CopyMemory(CopyData#,lparam&,12)
Groesse& = CopyData#.cbData&
Dim EigeneDaten#, Groesse&
CopyMemory(EigeneDaten#,CopyData#.lpData&,Groesse&)
Text$ = String $(EigeneDaten#,0)
Dispose EigeneDaten#
EndIf
return call(AltProc&,wnd&,msg&,wparam&,lparam&)
Endproc
AltProc&=~SetWindowLong(%hwnd,~GWL_WNDPROC,ProcAddr("WndProc",4))
While 1
ProgHndl&=FindWindow("PROGRAMM2")//> for Program 2 these row Remove
//ProgHndl&=FindWindow("PROGRAMM1")//< and these row insert
Case ProgHndl&: Break
Sleep 100
EndWhile
User Messages ~WM_COPYDATA
WhileNot end%
WaitInput
If %Key = 2
Let end% = 1
ElseIf GetFocus(EndeBtn&)
Let end% = 1
ElseIf GetFocus(SendeBtn&)
Send GetText$(Edit&)
ElseIf %umessage=~WM_COPYDATA
SetText Edit&, Text$
Endif
EndWhile
Dispose CopyData#
End
PROGRAMM2:
'INTER-PROGRAMM KOMMUNIKATION
'by Rudger tailor, 06.04.2007
'two programs swap data by WM_COPYDATA from. simply one Program create and then,
'around the second Program to create, The three marked Lines in the View source by the
'auskommentierten Lines supplant. The Text in the Edit appear to pressing the send-Buttons
'in the Edit the others Program. ex Profan 8 because of ProcAddr()
'"Vielleicht can it Yes someone brauchen".
'((Vkejjb))-Grant by Rudger tailor, 06.04.2007 on XProfan.net
Def CopyMemory(3) !"KERNEL32","RtlMoveMemory"
$H C:\Program Files (x86)\XProfan11\INCLUDE\Structs.ph
$H C:\Program Files (x86)\XProfan11\INCLUDE\Messages.ph
$H C:\Program Files (x86)\XProfan11\INCLUDE\windows.ph
Declare end%, SendeBtn&, EndeBtn&, Edit&
Declare Groesse&, Text$, ProgHndl&, AltProc&
Declare CopyData#, EigeneDaten#
Struct SCopyData = ~COPYDATASTRUCT
Dim CopyData#, SCopyData
Window Style 538
'Window Title "PROGRAMM1" //> for Program 2 these Lines Remove
'Window Int(%MaxX / 2 - 200),Int(%MaxY / 2 - 100)-195,100//>
Window Title "PROGRAMM2"//< and these Lines insert
Window Int(%MaxX / 2 + 5),Int(%MaxY / 2 - 100)-195,100
Set("FastMode",1)
EndeBtn& = Create("Button",%hWnd,"Beenden",105,50,70,20)
SendeBtn& = Create("Button",%hWnd,"Senden",15,50,70,20)
Edit& = Create("Edit", %hWnd,"", 10, 15, 170, 24)
Proc Send
Parameters Message$
With CopyData#
.dwData& = 0
.cbData& = SizeOf(Message$)
.lpData& = Addr(Message$)
EndWith
Sendmessage(ProgHndl&,~WM_COPYDATA,%hWnd,Addr(CopyData#))
ENDPROC
Proc WndProc
parameters wnd&, msg&, wparam&, lparam&
If msg&=~WM_COPYDATA
CopyMemory(CopyData#,lparam&,12)
Groesse& = CopyData#.cbData&
Dim EigeneDaten#, Groesse&
CopyMemory(EigeneDaten#,CopyData#.lpData&,Groesse&)
Text$ = String $(EigeneDaten#,0)
Dispose EigeneDaten#
EndIf
return call(AltProc&,wnd&,msg&,wparam&,lparam&)
Endproc
AltProc&=~SetWindowLong(%hwnd,~GWL_WNDPROC,ProcAddr("WndProc",4))
While 1
'ProgHndl&=FindWindow("PROGRAMM2")//> for Program 2 these row Remove
ProgHndl&=FindWindow("PROGRAMM1")//< and these row insert
Case ProgHndl&: Break
Sleep 100
EndWhile
User Messages ~WM_COPYDATA
WhileNot end%
WaitInput
If %Key = 2
Let end% = 1
ElseIf GetFocus(EndeBtn&)
Let end% = 1
ElseIf GetFocus(SendeBtn&)
Send GetText$(Edit&)
ElseIf %umessage=~WM_COPYDATA
SetText Edit&, Text$
Endif
EndWhile
Dispose CopyData#
End
|
| | | XProfan 11Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 11/27/18 ▲ |
| |
| | | SetWindowLong GWL_WNDPROC on a Proc (instead of mind. nProc) is definitiv a problem - "verstärkend" To there To "fahrlässig".
here of course (only) in the Context with User Messages attempts To treat: [...]
Author: David Strutz (---.dip0.t-ipconnect.de) date: 27.04.16 19:20 User Messages dürften unfortunately for wm_copydata not at all uses go because the address behind the memory not any more sure is, because User Messages long ago receive get before tappt im dunkeln (asynchron) from WaitInput out manage and the Transmitter whom allozierten memory (lparam) not unmöglich in the meantime anderweitig uses. thereafter remaining then datensicherer receptions in a subclassproc, The against can however Aussetzer and have it could above wm_copydata Messages overlooking go. thereafter remaining then means only a Own wProc, these against should then but too a nProc his since the App otherwise anytime crash could because ProcAddr on a XProfan-Proc unfortunately only for Enumeration instead of too for APCs uses go must. IMHO goes sicheres wm_copydata-receive with XProfan then in link with of/ one nProc as wndProc. @Roland: I am not sure whether I you already demand having, whether You with the wm_copydata-Message in your "default" wProc (be it The for hWnd) not a exception regulate could so the memory behind lParam too really available standing and sure To receive is too without nProcs-Workaround. it would too integrally simply To release mere only with 1 weiterem memory to Laufzeit there only 1 Thread: comes wm_copydata, then becomes the memory (re-)dimensioniert and the Content from lparam copies, and lastly, lparam on The address the own Speichers settle. wm_copydata is a the wertvollsten Messages. XProfan & FreeProfan rox: [...] Message machine (27.04.16 19:27)
thereafter time try a nProc "wnd_proc" To use.
//Mainwindow Subclassing
declare owp&
cls
owp&=setWindowLong(hWnd,gwl_wndProc,procaddr(hWnd.wndProc,4))
waitinput
end
nProc hWnd.wndProc
Parameters wnd&,msg&,wp&,lp&
global owp&
return callWindowProc(owp&,wnd&,msg&,wp&,lp&)
endproc
so wären possible Speicherlecks at least eingebannt. |
| | | | |
|
Zum QuelltextThemeninformationenthis Topic has 3 subscriber: |