#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=ipc_receiver.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include #include #include #include #include #include ; Author : Grosminet Global Const $FunctionIdentifier = 314145 Global Const $sAPP_me = "ipc_receiver" Global Const $sAPP_other = "ipc_sender" Global Const $tagCOPYDATASTRUCT = "struct;ulong_ptr dwData;dword cbData;ptr lpData;endstruct" Global $MyCDS = DllStructCreate($tagCOPYDATASTRUCT) Global $OwnWinHandle Global Const $sSenderEXE = @scriptdir & "\" & $sAPP_other & ".exe" Global $guiw = 1000, $guih = 300, $guix = (@desktopwidth - $guiw - 50), $guiy = 100, $sp = 10, $x = $sp, $y = $sp, $w, $hbut = 28, $h Global $hParentGUI, $hlocalPID, $hRecEdit Global $debug = true, $info, $hProcessOther, $PIDAppMe, $PIDAppOther, $iRead, $aret ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo $hParentGui = GUICreate($sAPP_me, $guiw, $guih, $guix, $guiy) $w = ($guiw - 2*$sp) $hlocalPID = GUIctrlCreateLabel("PID=", $x, $y, $w, $hbut) $y += $hbut + $sp $h = ($guih - $y - $sp) $hRecEdit = GUIctrlCreateEdit("", $x, $y, $w, $h) GUICtrlSetFont(-1, 9, $FW_NORMAL, Default, "Courier New") ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo GUIRegisterMsg($WM_COPYDATA, 'WM_FROM_APP') GUISetState(@SW_SHOW, $hParentGui) GUICtrlSetData($hlocalPID, "PID= " & @AutoItPID) ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo ; Get the SENDER application 'pid' ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo $PIDAppOther = ShellExecute($sSenderEXE) if $PIDAppOther = -1 then MsgBox($MB_SYSTEMMODAL, "ERROR", "Unable to start " & $sAPP_other & " --> error= " & @error) exit Endif sleep(500) $info = "Ready to receive ! Please send a text ..." & @CRLF _ShowInfo($info) ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo ; Get the SENDER application 'process handle' ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo $hProcessOther = _WinAPI_OpenProcess($PROCESS_VM_READ, False, $PIDAppOther) if @error Then $info = "_WinAPI_OpenProcess() error: " & @error & @crlf _ShowInfo($info) exit endif ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _myExit() EndSwitch WEnd ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo Func WM_FROM_APP($hWnd, $iMsg, $wParam, $lParam) local $tMyCDS = DllStructCreate($tagCOPYDATASTRUCT, $lParam) $info = "... WM_FROM_APP() ... data received ..." & @crlf ; Global Const $tagCOPYDATASTRUCT = "struct;ulong_ptr dwData;dword cbData;ptr lpData;endstruct" ; dwData ; function identifier ; cbData ; size of data ; lpData ; data structure Local $iStrucSize_SENT = Int(DllStructGetData($tMyCDS, "cbData")) Local $pBuffer = DllStructGetData($tMyCDS, "lpData") Local $FctID = DllStructGetData($tMyCDS, "dwData") $info &= "dwData: " & $FctID & @crlf $info &= "cbData: " & $iStrucSize_SENT & @crlf $info &= "lpData: " & $pBuffer & @crlf _ShowInfo($info) ; local $TagInfoStruct = "struct;align;byte buf[" & $iStrucSize_SENT & "];endstruct" Local $tbuffer = DllStructCreate($TagInfoStruct, $pBuffer) Local $iSizeStruct = DllStructGetSize($tbuffer) Local $sStringReceived = DllStructGetData($tbuffer, "buf") ; $info = "... WM_FROM_APP() ... String sent ..." & @crlf $info &= "String: " & $sStringReceived & @crlf _ShowInfo($info) _ShowInfo(_DumpStruct($pBuffer, $iStrucSize_SENT)) _ShowInfo(_WinAPI_GetString($pBuffer) & @crlf & "--------------------------------" & @crlf) EndFunc ;==>WM_FROM_APP ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo Func _ShowInfo($msg) if $debug then ConsoleWrite($msg) GUICtrlSetData($hRecEdit, GUICtrlRead($hRecEdit) & $msg) Local $iEnd = StringLen(GUICtrlRead($hRecEdit)) _GUICtrlEdit_SetSel($hRecEdit, $iEnd, $iEnd) _GUICtrlEdit_Scroll($hRecEdit, $SB_SCROLLCARET) Endfunc ; _ShowInfo ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo Func _myExit() _WinAPI_CloseHandle($hProcessOther) ProcessClose($PIDAppOther) GUIDelete() exit Endfunc ; _myExit ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo Func _DumpStruct($p_STRUCT, $iSizeStruct) ; $iSizeStruct = the size of the struct in bytes (DllStructGetSize) Local $TagStructDump = "struct;align;byte[" & $iSizeStruct & "];endstruct" Local $t_Struct = DllStructCreate($TagStructDump, $p_STRUCT) Local $i Local $structInfo = "" _ConsoleWriteInfo($structInfo, "Structure size: " & $iSizeStruct & " byte(s):" & @crlf) for $i = 0 to $iSizeStruct - 1 _ConsoleWriteInfo($structInfo, hex(DllStructGetData($t_Struct, 1, $i), 2) & " ") if (Mod($i+1, 8) = 0) then _ConsoleWriteInfo($structInfo, @CRLF) Endif Next _ConsoleWriteInfo($structInfo, @CRLF) return $structInfo EndFunc ; _DumpStruct ; ooooooooooooooooooooooooooooooooooooooooooooooooooooooo Func _ConsoleWriteInfo(ByRef $msg, $txt) $msg &= $txt EndFunc ; _ConsoleWriteInfo #cs // ************ Globals ************ // #define MYDISPLAY 1 typedef struct tagMYREC { char s1[80]; char s2[80]; DWORD n; } MYREC; PCOPYDATASTRUCT pMyCDS; void WINAPI MyDisplay( LPSTR, LPSTR, DWORD ); // // ************ Code fragment **************** // case WM_COPYDATA: pMyCDS = (PCOPYDATASTRUCT) lParam; switch( pMyCDS->dwData ) { case MYDISPLAY: MyDisplay( (LPSTR) ((MYREC *)(pMyCDS->lpData))->s1, (LPSTR) ((MYREC *)(pMyCDS->lpData))->s2, (DWORD) ((MYREC *)(pMyCDS->lpData))->n ); } break; #ce