Sign in to follow this  
Followers 0
Iczer

IPC with DLLStructure

3 posts in this topic

I wanted to make IPC between 2 autoit scripts via shared in memory dll structure so both scripts can read/write in it.

But it not works as i coded it - it seems is access rights issue. What i can do about it?

Script_A:

#AutoIt3Wrapper_UseX64=y
#include-once
#include <WinAPISys.au3>
#include <Memory.au3>
;==========================================================================================
$tagInfo = "struct;HWND hMainHandle;WORD iID;WCHAR Line[512];endstruct"
;==========================================================================================
ConsoleWrite($tagInfo & @CRLF)

$tInfo = DllStructCreate($tagInfo)
If @error Then MsgBox(64,"DllStructCreate","@error = "&@error)

$tInfo.Line = "ksifjvnskfjvnzaksfjvnskalfjvnaKLJSNLKDvsdvsdcvsc vn"
If @error Then MsgBox(64,"DllStructSetData","@error = "&@error)

$ptrInfo  = DllStructGetPtr ($tInfo)
$sizeInfo = DllStructGetSize($tInfo)

$hGMem = _MemGlobalAlloc($sizeInfo, $GMEM_MOVEABLE)
$ptrGMem = _MemGlobalLock($hGMem)
_MemMoveMemory($ptrInfo, $ptrGMem, $sizeInfo)
_MemGlobalUnlock ($hGMem)

RunWait("Script_B.exe " & String($ptrInfo) & " " & $sizeInfo)

RunWait("Script_B.exe " & String($ptrGMem) & " " & $sizeInfo)

Exit

 

Script_B:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include-once
#include <WinAPISys.au3>




;==========================================================================================
$tagInfo = "struct;HWND hMainHandle;WORD iID;WCHAR Line[512];endstruct"
;==========================================================================================
$ptrInfo = Ptr($CmdLine[1])
$sizeInfo = Int($CmdLine[2])

$tInfo = DllStructCreate($tagInfo, $ptrInfo)
If @error Then MsgBox(64,"DllStructCreate",@error)

MsgBox(64,"Script_B.1", "Struct Pointer : " & Ptr($CmdLine[1])& @CRLF & _
                    "IsPtr()        = " & IsPtr($ptrInfo)& @CRLF & _
                    "Struct Size    = " & $sizeInfo & @CRLF & _
                    "_WinAPI_IsBadReadPtr()  = " & _WinAPI_IsBadReadPtr($ptrInfo, $sizeInfo) & @CRLF & _
                    "_WinAPI_IsBadWritePtr() = " & _WinAPI_IsBadWritePtr($ptrInfo, $sizeInfo))

MsgBox(64,"Script_B.2", "String Recieved : " & $tInfo.Line)

Exit

 

Share this post


Link to post
Share on other sites



could be done this way...

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include-once
#include <WinAPISys.au3>


;==========================================================================================
$tagInfo = "struct;HWND hMainHandle;WORD iID;WCHAR Line[512];endstruct"
;==========================================================================================
$ptrInfo = Ptr($CmdLine[1])
$sizeInfo = Int($CmdLine[2])

$tInfo = DllStructCreate($tagInfo)
$tptr=dllstructgetptr($tinfo)
$tsize=DllStructGetSize($tinfo)
If @error Then MsgBox(64,"DllStructCreate",@error)

$pid=Processwait("Script_A.exe")
$process = _WinAPI_OpenProcess(0xFFFF, False, $pid)
$bytes=0
$a=_WinAPI_ReadProcessMemory($process,$ptrInfo,$tptr,$tsize,$bytes)


MsgBox(64,"Script_B.1", "Struct Pointer : " & Ptr($CmdLine[1])& @CRLF & _
                    "IsPtr()        = " & IsPtr($ptrInfo)& @CRLF & _
                    "Struct Size    = " & $sizeInfo & @CRLF & _
                    "_WinAPI_IsBadReadPtr()  = " & _WinAPI_IsBadReadPtr($ptrInfo, $sizeInfo) & @CRLF & _
                    "_WinAPI_IsBadWritePtr() = " & _WinAPI_IsBadWritePtr($ptrInfo, $sizeInfo))

MsgBox(64,"Script_B.2", "String Recieved : " & $tInfo.Line)

Exit

 

Share this post


Link to post
Share on other sites

hmm...  _WinAPI_IsBadReadPtr() _WinAPI_IsBadReadPtr() still "1"  but if debug privileges $bDebugPriv = True in _WinAPI_OpenProcess() then it works and second MsgBox() return string from "Line"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0