English
Source / code snippets

Copydata communication Prozessen Wmcopydata

 

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
 
Perbody is nofect !
04/06/07  
 




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 11
Computer: 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.
 
12/05/18  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

7.125 Views

Untitledvor 0 min.
H.Brill10/17/22
Stefan8101/02/20
Pedro Miguel05/26/19
Michael Borowiak03/07/19
More...

Themeninformationen

this Topic has 3 subscriber:

iF (1x)
p.specht (1x)
R.Schneider (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie