Jump to content

Need GUI'less example of communication between scripts


topten
 Share

Recommended Posts

  • Moderators

topten,

Of course - the GUIs are usually there so you can see the sent/received data.  Here are 2 scripts without GUIs - compile both and run the parent:

MailSlot_Parent,au3:

#include <MsgBoxConstants.au3>
#include "MailSlot.au3"

HotKeySet("{ESC}", "_Exit")

; Create the Mailslot

$sMailSlotName = "\\.\mailslot\trancexxudf"
$hMailSlot = _MailSlotCreate($sMailSlotName)
If @error Then
    MsgBox(48, "MailSlot for Label_Master", "Failed to create account!")
    Exit
EndIf



; Run child
ShellExecute("MailSlot_Child.exe", $sMailSlotName)

While 1
    Sleep(10)
    ; Is there a message?
    Local $iSize = _MailSlotCheckForNextMessage($hMailSlot)
    If $iSize Then
        ; If so then read it
        $sMessage = _MailSlotRead($hMailSlot, $iSize, 1)
        ; Announce content
        MsgBox($MB_SYSTEMMODAL, "Message from Parent", "Received: " & $sMessage)
    EndIf

WEnd



Func _Exit()
    Exit
EndFunc

Mailslot_Child.au3:

#include <MsgBoxConstants.au3>
#include "MailSlot.au3"

If $CmdLine[0] = 0 Then Exit

; Read MailSlot name
$sMailSlotName = $CmdLine[1]

; Start timer
$nBegin = TimerInit()

While 1
    Sleep(10)

    If TimerDiff($nBegin) > 20 * 1000 Then
        ; Random uppercase letter
        $sMessage = Chr(Random(65, 90, 1))
        ; Announce sending
        MsgBox($MB_SYSTEMMODAL, "Message from Child", "Sending: " & $sMessage)
        ; Send
        _MailSlotWrite($sMailSlotName, $sMessage)
        ; Reset timer
        $nBegin = TimerInit()
    EndIf



    If Not ProcessExists("MailSlot_Parent.exe") Then
        Exit
    EndIf

WEnd

Keep the same names as I have hard-coded them for simplicity. You will obviously also need trancexx's MailSlot UDF:

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

You can also create message only windows using the CreateWindowEx api.  But that may be more useful in multi-thread programs.  May work with a timer but I haven't tried it.  I used it as a scheme to pass the command line to the primary instance of a program with WM_COPYDATA.  But there are lots of IPC you can use.  Windows does a lot with named memory mapped files.  If you can pass your data with a single page of memory then you can map the file using the page file as backing, rather than creating an actual disk file, even if the system has no paging file(virtual memory set to 0.)  Windows must make a temp file under the covers or just remap it to some memory in the system.  I don't know how it does it but I tried it and it does work.

Just rambling on.  :)

 

Edited by MilesAhead
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...