Sign in to follow this  
Followers 0
anixon

Coms between Scripts

3 posts in this topic

At the moment I have two scripts running similtaneously which on occasions need to communicate with each other by pass from one to the other a simple processing switch/flag 1 to process 0 not to process.

At the moment I am writing the switch/ flag to an ini file which is read by the processing script. This method on occasions may cause a write read timing issue base on where the scripts processing cycle is at. In other words it misses a process and has to wait for the next cycle.

Is their any way that scripts can read a global variable like Global $Process = 1 that is a unique variable in another script.

Assistance is always appreciated. Ant.. :x

Share this post


Link to post
Share on other sites



anixon,

If you search for "+inter +process +communication" you will find a fair number of such things on the forum. My personal favourites are trancexx's MailSlot UDF and the one from Yashied on which this is based:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; Based on code from Yashied

#include <GUIConstantsEx.au3>
#Include <WinApi.au3>

Opt("WinTitleMatchMode", 3)

Global Const $WM_MYMSG = _WinAPI_RegisterWindowMessage('WM_MYMSG')
Global Const $HWND_BROADCAST = 0xFFFF
Global $sThis_Win_Title, $sThat_Win_Title
Global $iY, $hInput, $hButton, $hLabel
Global $iValue_To_Send
Global $iValue_Rcvd = Default

; Set GUI title
If WinExists("First Instance") Then
    If WinExists("Second Instance") Then Exit
    $sThis_Win_Title = "Second Instance"
    $sThat_Win_Title = "First Instance"
    $iY = 300
Else
    $sThis_Win_Title = "First Instance"
    $sThat_Win_Title = "Second Instance"
    $iY = 100
EndIf

; Create GUI
$hGUI = GUICreate($sThis_Win_Title, 400, 150, 100, $iY)

$hInput = GUICtrlCreateInput("", 20, 20, 360, 20)
$hButton = GUICtrlCreateButton("Send", 160, 60, 80, 30)
$hLabel = GUICtrlCreateLabel("", 20, 100, 360, 20)

GUIRegisterMsg($WM_MYMSG, 'WM_MYMSG')

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ; Send exit message to all windows
            _WinAPI_PostMessage($HWND_BROADCAST, $WM_MYMSG, -999999, $hGUI)
        Case $hButton
            ; Send message to other window
            $sValue_To_Send = Number(GUICtrlRead($hInput))
            If IsNumber($sValue_To_Send) Then _WinAPI_PostMessage($HWND_BROADCAST, $WM_MYMSG, $sValue_To_Send, $hGUI)
            GUICtrlSetData($hInput, "")
    EndSwitch

    ; Check messages received
    If $iValue_Rcvd = -999999 Then Exit
    If $iValue_Rcvd <> Default Then
        GUICtrlSetData($hLabel, Number($iValue_Rcvd))
        $iValue_Rcvd = Default
    EndIf

WEnd

Func WM_MYMSG($hWnd, $iMsg, $wParam, $lParam)
    ; Only react if sent from another GUI
    If $lParam <> $hGUI Then $iValue_Rcvd = $wParam
    ; Unless it is the exit signal
    If $wParam = -999999 Then $iValue_Rcvd = $wParam
EndFunc   ;==>WM_MYMSG

Just compile and run the exe twice. :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

anixon,

If you search for "+inter +process +communication" you will find a fair number of such things on the forum. My personal favourites are trancexx's MailSlot UDF and the one from Yashied on which this is based:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; Based on code from Yashied

#include <GUIConstantsEx.au3>
#Include <WinApi.au3>

Opt("WinTitleMatchMode", 3)

Global Const $WM_MYMSG = _WinAPI_RegisterWindowMessage('WM_MYMSG')
Global Const $HWND_BROADCAST = 0xFFFF
Global $sThis_Win_Title, $sThat_Win_Title
Global $iY, $hInput, $hButton, $hLabel
Global $iValue_To_Send
Global $iValue_Rcvd = Default

; Set GUI title
If WinExists("First Instance") Then
    If WinExists("Second Instance") Then Exit
    $sThis_Win_Title = "Second Instance"
    $sThat_Win_Title = "First Instance"
    $iY = 300
Else
    $sThis_Win_Title = "First Instance"
    $sThat_Win_Title = "Second Instance"
    $iY = 100
EndIf

; Create GUI
$hGUI = GUICreate($sThis_Win_Title, 400, 150, 100, $iY)

$hInput = GUICtrlCreateInput("", 20, 20, 360, 20)
$hButton = GUICtrlCreateButton("Send", 160, 60, 80, 30)
$hLabel = GUICtrlCreateLabel("", 20, 100, 360, 20)

GUIRegisterMsg($WM_MYMSG, 'WM_MYMSG')

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ; Send exit message to all windows
            _WinAPI_PostMessage($HWND_BROADCAST, $WM_MYMSG, -999999, $hGUI)
        Case $hButton
            ; Send message to other window
            $sValue_To_Send = Number(GUICtrlRead($hInput))
            If IsNumber($sValue_To_Send) Then _WinAPI_PostMessage($HWND_BROADCAST, $WM_MYMSG, $sValue_To_Send, $hGUI)
            GUICtrlSetData($hInput, "")
    EndSwitch

    ; Check messages received
    If $iValue_Rcvd = -999999 Then Exit
    If $iValue_Rcvd <> Default Then
        GUICtrlSetData($hLabel, Number($iValue_Rcvd))
        $iValue_Rcvd = Default
    EndIf

WEnd

Func WM_MYMSG($hWnd, $iMsg, $wParam, $lParam)
    ; Only react if sent from another GUI
    If $lParam <> $hGUI Then $iValue_Rcvd = $wParam
    ; Unless it is the exit signal
    If $wParam = -999999 Then $iValue_Rcvd = $wParam
EndFunc   ;==>WM_MYMSG

Just compile and run the exe twice. :P

M23

Thanks M23 that works perfectly I will however need to do some mods to remove the user input and 'send' functionality and given that the messaging is one way only there is probably no need for two windows. Great help like this is always appreciated thanks again. Ant.. :x

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