Page 1 sur 1
Communication Inter-Exe
Publié : sam. 05/mai/2007 21:05
par Droopy
Salut
Je souhaiterais faire communiquer deux programmes ( en Purebasic bien entendu

).
J'ai trouvé plein de code sur le forum qui permettent cela
- Via des callback ( avec SendMessage )
- Via une zone mémoire partagée )
Mais ils ne fonctionnent pas si les deux programmes ne sont pas lancés avec le même compte utilisateur ( Un est lancé avec RunAs )
Auriez vous une idée pour les faire communiquer dans ce cas ?
Publié : sam. 05/mai/2007 21:12
par Anonyme2
Essayes avec les pipes (canaux de communication)
Microsoft dit ceci
A pipe is a section of shared memory that processes use for communication. The process that creates a pipe is the pipe server. A process that connects to a pipe is a pipe client. One process writes information to the pipe, then the other process reads the information from the pipe. This overview describes how to create, manage, and use pipes.
Je pense que tu comprends
Publié : sam. 05/mai/2007 21:35
par brossden
Pour moi les pipes c'est autre chose....
Pour ma femme aussi du reste, et je n'ai aucune envie qu'elle change de définition !

Publié : sam. 05/mai/2007 23:26
par pastor
Bonjour,
A propos de pipes, aujourd'hui j'ai travaillé dessus

c'était la première fois et je ne suis pas vraiment doué

, voici un exemple de ping piloté par des pipes que j'ai récupéré sur le forum Anglais :
Ca peut aider à comprendre comment ca marche... sinon on peut toujours demander à nos femmes

.
Code : Tout sélectionner
; Redirect Outputs into Memory
; coded by Siegfried Rings march 2002
; redirected the pipes
;
;see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q173085
;
mCommand.s="ping 127.0.0.1"
;Structure used by the CreateProcessA function
;another then that Fred implemented !
Structure MySTARTUPINFO
cb.l
lpReserved.l
lpDesktop.l
lpTitle.l
dwX.l
dwY.l
dwXSize.l
dwYSize.l
dwXCountChars.l
dwYCountChars.l
dwFillAttribute.l
dwFlags.l
wShowWindow.w
cbReserved2.w
lpReserved2.l
hStdInput.l
hStdOutput.l
hStdError.l
EndStructure
proc.PROCESS_INFORMATION ;Process info filled by CreateProcessA
ret.l ;long variable For get the Return value of the
start.MySTARTUPINFO ;StartUp Info passed To the CreateProceeeA
sa.SECURITY_ATTRIBUTES ;Security Attributes passeed To the
hReadPipe.l ;Read Pipe handle created by CreatePipe
hWritePipe.l ;Write Pite handle created by CreatePipe
lngBytesread.l ;Amount of byte Read from the Read Pipe handle
strBuff.s=Space(256) ;String buffer reading the Pipe
;Consts For functions
#NORMAL_PRIORITY_CLASS = $20
#STARTF_USESTDHANDLES = $100
#STARTF_USESHOWWINDOW = $1
;Create the Pipe
sa\nLength =SizeOf(SECURITY_ATTRIBUTES) ;Len(sa)
sa\bInheritHandle = 1
sa\lpSecurityDescriptor = 0
ret = CreatePipe_(@hReadPipe, @hWritePipe, @sa, 0)
If ret = 0
;If an error occur during the Pipe creation exit
MessageRequester("info", "CreatePipe failed. Error: ",0)
End
EndIf
start\cb = SizeOf(MySTARTUPINFO)
start\dwFlags = #STARTF_USESHOWWINDOW | #STARTF_USESTDHANDLES
;set the StdOutput And the StdError output To the same Write Pipe handle
start\hStdOutput = hWritePipe
start\hStdError = hWritePipe
;Execute the command
ret = CreateProcess_(0, mCommand, sa, sa, 1, #NORMAL_PRIORITY_CLASS, 0, 0, @start, @proc)
If ret <> 1
MessageRequester("Info","File Or command not found", 0)
End
Else
;MessageRequester("Info","PRG started..:",0)
EndIf
;Now We can ... must close the hWritePipe
ret = CloseHandle_(hWritePipe)
mOutputs.s = ""
;Read the ReadPipe handle
While ret<>0
ret = ReadFile_(hReadPipe, strBuff, 255, @lngBytesread, 0)
If lngBytesread>0
mOutputs = mOutputs + Left(strBuff, lngBytesread)
EndIf
Wend
;Close the opened handles
ret = CloseHandle_(proc\hProcess)
ret = CloseHandle_(proc\hThread)
ret = CloseHandle_(hReadPipe)
;ret=CloseHandle_(hWritePipe)
;Return the Outputs property with the entire DOS output
MessageRequester("Info",mOutputs,0)
Publié : sam. 05/mai/2007 23:58
par Droopy
Merci à tous

, j'ai trouvé ce que je voulais
Code : Tout sélectionner
; Prog1
; *****************************************************************************
Global *data_in.COPYDATASTRUCT
Global data_out.COPYDATASTRUCT
Procedure WndProc(hwnd, uMsg, wParam, lParam)
If uMsg = #WM_COPYDATA
*data_in = lParam
temp.s = PeekS(*data_in\lpData)
SetGadgetText(0, temp)
ProcedureReturn #True
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 300, 200, "Prog1")
CreateGadgetList(WindowID(0))
StringGadget(0,0,0,300,24,"Test")
ButtonGadget(1,0,28,300,24, "Send")
SetWindowCallback(@WndProc())
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
hwnd = FindWindow_(0, "Prog2")
If hwnd
temp.s = GetGadgetText(0)
data_out\cbData = Len(temp) + 1 ; Nullbyte
data_out\lpData = @temp ; Zeiger auf Daten
SendMessage_(hwnd, #WM_COPYDATA, WindowID(0), data_out)
EndIf
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
Génial ce que l'on trouve sur ces forums

Publié : dim. 06/mai/2007 8:16
par Anonyme2
brossden a écrit :Pour moi les pipes c'est autre chose....
Dans un de mes outil j'utilise un pipe, mais la communication se fait entre une application que je lance et mon code.
brossden a écrit :Pour ma femme aussi du reste, et je n'ai aucune envie qu'elle change de définition !

C'est bien ce que je dis, c'est un canal de communication
Droopy, il me semble que sur le site de Freak, il y a un code pour communiquer qui utilise les messages (Sendmessage_(), avec un exemple
Publié : dim. 06/mai/2007 14:03
par Droopy
Droopy, il me semble que sur le site de Freak, il y a un code pour communiquer qui utilise les messages (Sendmessage_(), avec un exemple
Oui mais il ne fonctionne pas si les deux EXE ne sont pas lancés avec le même compte utilisateur

Publié : dim. 06/mai/2007 17:00
par Kwai chang caine
Bonjour droopy
Il est genial ton code (Normal me dira tu....

), en plus ce qui est top c'est qu'il est court
Mais crois tu que l'on pourrais l'adapter pour qu'il puisse communiquer avec un programme fait en VB, j'en aurais trop besoin.
Si oui, dans un forum VB, dans quelle direction crois-tu que je devrais chercher pour pouvoir le faire fonctionner avec ton genial et court code.
Bravo

Publié : dim. 06/mai/2007 18:09
par Droopy
Ce code n'est pas de moi, je l'ai trouvé sur le forum US.
Si VB gère les CallBack ( je n'en sais rien ), je pense qu'il n'y a pas de soucis

Publié : dim. 06/mai/2007 20:11
par Kwai chang caine
Aaah je croyais qu'il etait de toi.
C'est pas grave, il est bon de rendre a cesar .......mais il est genial quand meme.
Je crois que VB gere les callback, je ne peux pas le jurer puisque les callback c'est de la prog avancée, et je n'ai pas encore le niveau.
Par contre j'ai déjà vu enumcallback etc ....donc c'est bon signe
Merci de ta reponse