Jump to content

Interprocess communication help


Champak
 Share

Recommended Posts

So I'm trying to figure out the best interprocess communication app to use. I've tested two, one works fine I guess but I'm just not sure about its functions and I'm waiting on a reaponse from the developer; the other one broke something in my computer (yes I'm blaming it on the udf https://www.autoitscript.com/forum/topic/179335-i-think-i-have-a-shell-problem-with-ie/?do=findComment&comment=1287383).

So I'v been researching for about two weeks now and here's what I came up with:

Ws_copydata from guinness (waiting for answers) -- https://www.autoitscript.com/forum/topic/119502-solved-wm_copydata-x64-issue/
Mailslot from trancexx -- https://www.autoitscript.com/forum/topic/106710-mailslot/?page=2
Interprocess from jscript -- https://www.autoitscript.com/forum/topic/127615-interprocess-udf-runs-a-remote-function/
Container from mrcreator (broke my computer ) -- https://www.autoitscript.com/forum/topic/126936-container-udf-scripts-interaction-library/?page=1
And a pipes udf in the help file with no examples


All of these are old so i'm wondering if anyone came up with anything new first that I haven't seen. If not...Which of these are the best? Features, speed, and efficiency in your opinion?


What I'm interested in doing? All four are autoit apps, I'm looking to:

1/ activate functions in the other app.
2/ pass variables.
3/ pass multi d arrays -- (i guess with this i have to turn it to a string first, but is that efficient).
4/ two way communication.


Thanks for any help or insight.

Edited by Champak
Link to comment
Share on other sites

  • Moderators

Champak,

Personally I use MailSlot. Looking at your list:

  1. Just pass a suitable string to the other function to run a function when received
  2. I believe it is limited to strings, but they can easily be recast to other datatypes on arrival
  3. See above
  4. Very easy to set up.

I have never had any problems with it and would recommend it highly.

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

  • Moderators

Champak,

This one works!

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

  1. I believe it is limited to strings, but they can easily be recast to other datatypes on arrival

Mailslot data is simply written/read as bytes, so it can be composed of anything as long as you know what data-types you're sending/receiving.

For example, you can collect any data-types you want into a structure and just send that struct as a single message... (in this case two int's, a double, and a widestring)

#include <APIErrorsConstants.au3>
#include <WinAPI.au3>
#include <WinAPIFiles.au3>

Global $BytesWritten, $BytesRead

Global $Struct = "int;int;double;wchar[512]"
Global $tBuffer = DllStructCreate($Struct), $InBuffer = DllStructCreate($Struct)

Global $hMailslot = _WinAPI_CreateMailslotW("\\.\Mailslot\Montaigne", DllStructGetSize($InBuffer), 1000)
If $hMailslot = $INVALID_HANDLE_VALUE Then Exit

Global $hMailslotOut = _WinAPI_CreateFileEx("\\.\Mailslot\Montaigne", $OPEN_EXISTING, $GENERIC_WRITE, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_ATTRIBUTE_NORMAL)

DllStructSetData($tBuffer, 1, -4)
DllStructSetData($tBuffer, 2, 55)
DllStructSetData($tBuffer, 3, 2.2)
DllStructSetData($tBuffer, 4, "Que sçay-je?")

_WinAPI_WriteFile($hMailslotOut, DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer), $BytesWritten)
_WinAPI_CloseHandle($hMailslotOut)

_WinAPI_ReadFile($hMailslot, DllStructGetPtr($InBuffer), DllStructGetSize($InBuffer), $BytesRead)

ConsoleWrite("Bytes Written: " & $BytesWritten & @LF & "Bytes Read: " & $BytesRead & @LF)
MsgBox(0, "", DllStructGetData($InBuffer, 1) & @LF & DllStructGetData($InBuffer, 2) & @LF & DllStructGetData($InBuffer, 3) & @LF & DllStructGetData($InBuffer, 4))

_WinAPI_CloseHandle($hMailslot)

Exit

Func _WinAPI_CreateMailslotW($sFilePath, $iSize, $iTimeout, $tSecurity = 0)
    Local $aRet = DllCall('kernel32.dll', 'handle', 'CreateMailslotW', 'wstr', $sFilePath, 'dword', $iSize, 'dword', $iTimeout, 'struct*', $tSecurity)
    If @error Then Return SetError(@error, @extended, 0)
    If $aRet[0] = Ptr(-1) Then Return SetError(10, _WinAPI_GetLastError(), 0)

    Return $aRet[0]
EndFunc

This is actually an absurd example (as it's a single process sending a message into its own mailslot to duplicate structure contents it already has), but it was the simplest way to show how it works.  In reality the client programme would be sending the $tBuffer message, while the server programme converts it to the $InBuffer struct, but you get the idea.  Mailslots don't actually care where the data originates (whether in a separate process or not).

Link to comment
Share on other sites

  • Moderators

Kilmatead,

Thanks for the detailed explanation.

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

What answers? WM_COPYDATA is what I have used in the past.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Do I need to make a mailslot for each function, or is there a way to add an extension of sorts so the receiving app knows where to route each communication? I'm thinking another parameter on the _MailSlotWrite and _MailSlotRead that I could use in the main loop as a switch instead of checking XX different times for XX different functions I may have waiting for information. Unless the way I'm looking at this UDF is incorrect and I'm not seeing something.

Edited by Champak
Link to comment
Share on other sites

I use the TCP functions for my communication.

I have a bunch of computers that auto-login, and auto-start my listener app on the desktop.  Then I have a second process that runs behind the desktop (started by a scheduled task) which sends a message to the listener to run our tests against our apps.

I've had no real issues with them in the past year and a half (although at first, there was a lot to do to make it robust).

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • Moderators

Champak,

Whenever I have used 2-way communication I have created a MailSlot for each of the participants so that messages can be correctly delivered.

Here is a short demo script I have put together showing how I have used the UDF in the past. You need to make several copies (changing an index in the title each time; e.g. Test_1, Test_2, etc) and then run them simultaneously (either compiled or as scripts). Once the instances are all open, press each "Update" button to make sure each instance has the addresses for them all and then send/receive to your heart's content!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <EditConstants.au3>
#include "MailSlot.au3"

; Create fill to hold MailSlot addresses
Global $sMailSlotListFile = @ScriptDir & "\MailSlotList.lst"
; MailSlot title for this instance
Global $sMailSlotTitle = StringRegExpReplace(@ScriptName, "\..*$", "")
; Random string to use as MailSlot name
Global $sRandomMailSlotname = _RandomStr()
; Form full address for mMilSlot

Global Const $sMailSlotName_Receive = "\\.\mailslot\" & $sRandomMailSlotname



; Add ths MailSlot to list file
IniWrite($sMailSlotListFile, "MailSlots", $sMailSlotTitle, $sRandomMailSlotname)

; Create the MailSlot

Global $hMailSlot = _MailSlotCreate($sMailSlotName_Receive)
If @error Then
    MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "MailSlot Error", "Failed to create initial MailSlot account")
    Exit
EndIf



; Global variables
Global $iNumberOfMessagesOverall

Global $sMailSlotName_Send = ""

; Create GUI
Global $hGUI = GUICreate($sMailSlotTitle, 450, 400, 3 * @DesktopWidth / 4 - 225, Default, Default, $WS_EX_TOPMOST)

GUICtrlCreateLabel("Message To Send To:", 10, 22, 150, 25)

; Combo to show current address list
Global $cSend_Combo = GUICtrlCreateCombo("", 180, 22, 200, 25)
; Update list
_UpdateMail()

; Edit to hold message to send
Global $cEdit_Send = GUICtrlCreateEdit("", 15, 50, 300, 50, $ES_AUTOVSCROLL)

GUICtrlCreateLabel("Message Received:", 10, 122, 150, 25)

; Create edit to hold received messages
Global $cEdit_Read = GUICtrlCreateEdit("", 15, 150, 300, 200, $ES_READONLY)

; Create buttons
Global $cButtonSend = GUICtrlCreateButton("&Send Mail", 330, 100, 100, 25)
Global $cButton_Update = GUICtrlCreateButton("&Update Accounts", 330, 50, 100, 25)
Global $cButtonRead = GUICtrlCreateButton("Read &Mail", 330, 150, 100, 25)
Global $cButtonCheckCount = GUICtrlCreateButton("&Check Mail Count", 330, 200, 100, 25)
Global $cButtonCloseAccount = GUICtrlCreateButton("Close Mail &Account", 330, 250, 100, 25)
Global $cButtonRestoreAccount = GUICtrlCreateButton("&Restore Account", 330, 300, 100, 25)
Global $cButtonCloseApp = GUICtrlCreateButton("&Exit", 330, 350, 100, 25)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $cButtonCloseApp

            IniDelete($sMailSlotListFile, "MailSlots", $sMailSlotTitle)
            Exit
        Case $cButtonSend

            If GUICtrlRead($cSend_Combo) = "" Then
                MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "No account selected!", 0, $hGUI)
            Else
                $sMailSlotName_Send = "\\.\mailslot\" & IniRead($sMailSlotListFile, "MailSlots", GUICtrlRead($cSend_Combo), "")
                If $sMailSlotName_Send <> "\\.\mailslot\" Then
                    _SendMail($sMailSlotName_Send)
                Else
                    MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo", "Invalid account.", 0, $hGUI)
                EndIf

            EndIf

        Case $cButton_Update
            _UpdateMail()
        Case $cButtonRead

            If $hMailSlot Then
                _ReadMessage($hMailSlot)
            Else
                MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo", "MailSlot does not exist", 0, $hGUI)
            EndIf

        Case $cButtonCheckCount

            If $hMailSlot Then
                _CheckCount($hMailSlot)
            Else
                MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo", "MailSlot does not exist", 0, $hGUI)
            EndIf

        Case $cButtonCloseAccount

            If $hMailSlot Then
                _CloseMailAccount($hMailSlot)
            Else
                MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "MailSlot does not exist", 0, $hGUI)
            EndIf

        Case $cButtonRestoreAccount

            If $hMailSlot Then
                MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "MailSlot already exists", 0, $hGUI)
            Else
                _RestoreAccount($sMailSlotName_Receive)
            EndIf

    EndSwitch



WEnd





; Wrapper functions:

Func _UpdateMail()

    Local $aMailSlots = IniReadSection($sMailSlotListFile, "MailSlots")

    If Not IsArray($aMailSlots) Then MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "No accounts available!", 0, $hGUI)

    Local $sMailSlotList = "|"
    For $i = 1 To $aMailSlots[0][0]
        If $aMailSlots[$i][1] <> $sRandomMailSlotname Then $sMailSlotList &= $aMailSlots[$i][0] & "|"
    Next
    GUICtrlSetData($cSend_Combo, $sMailSlotList)

EndFunc



Func _SendMail($sMailSlotName)

    Local $sDataToSend = GUICtrlRead($cEdit_Send)

    If $sDataToSend Then
        _MailSlotWrite($sMailSlotName, $sDataToSend);, 1)
        Switch @error
            Case 1
                MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "MialSlot does not exist", 0, $hGUI)
            Case 2
                MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "MailSlot blocked", 0, $hGUI)
            Case 3
                MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "Message sent but possible errors in future as open handle remains", 0, $hGUI)
            Case 4
                MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "MailSlot internal error", 0, $hGUI)
            Case Else
                MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "Message sent", 0, $hGUI)
        EndSwitch

        GUICtrlSetData($cEdit_Send, "")
    Else
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "No message to send", 0, $hGUI)
    EndIf



EndFunc   ;==>_SendMail



Func _ReadMessage($hHandle)

    Local $iSize = _MailSlotCheckForNextMessage($hHandle)

    If $iSize Then
        Local $sData = _MailSlotRead($hMailSlot, $iSize, 1)
        $iNumberOfMessagesOverall += 1
        GUICtrlSetData($cEdit_Read, "Message No" & $iNumberOfMessagesOverall & " , Size = " & $iSize & " :" & @CRLF & @CRLF & $sData)
    Else
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "Nothing read", "MailSlot empty", 0, $hGUI)
    EndIf



EndFunc   ;==>_ReadMessage





Func _CheckCount($hHandle)

    Local $iCount = _MailSlotGetMessageCount($hHandle)
    Switch $iCount

        Case 0
            MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "Messages", "No new messages", 0, $hGUI)
        Case 1
            MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "Messages", "There is 1 message waiting to be read", 0, $hGUI)
        Case Else
            MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "Messages", "There are " & $iCount & " messages waiting to be read", 0, $hGUI)
    EndSwitch



EndFunc   ;==>_CheckCount





Func _CloseMailAccount(ByRef $hHandle)

    If _MailSlotClose($hHandle) Then
        $hHandle = 0
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "Account succesfully closed", 0, $hGUI)
        IniDelete($sMailSlotListFile, "MailSlots", $sMailSlotTitle)
    Else
        MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "Account could not be closed!", 0, $hGUI)
    EndIf



EndFunc   ;==>_CloseMailAccount





Func _RestoreAccount($sMailSlotName_Receive)

    Local $hMailSlotHandle = _MailSlotCreate($sMailSlotName_Receive)

    If @error Then
        MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "Account could not be created", 0, $hGUI)
    Else
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "New account with the same address successfully created", 2, $hGUI)
        $hMailSlot = $hMailSlotHandle ; global var

        IniWrite($sMailSlotListFile, "MailSlots", $sMailSlotTitle, $sRandomMailSlotname)
    EndIf



EndFunc   ;==>_RestoreAccount



Func _RandomStr()
    Local $sString

    For $i = 1 To 13
        $sString &= Chr(Random(97, 122, 1))
    Next
    Return $sString

EndFunc   ;==>__RandomStr

There is a file created in the same folder which holds the instance name and associated address - think of it as a phone directory. When each instance is created it adds its details to the file - using the buttons on the GUI you can destroy and then recreate the MailSlot for each instance which will be reflected in the directory when you update.

Please ask if you have any further questions.

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

The ini file is a great idea, but I went a different route, but still need a little help. I decided to add a switch to the _MailSlotWrite and also add the ability to pass single arrays. My issue is how do I turn what was a multi-d array back into a multi-d array? So if anyone can help on that...or improve what I've done all together.

First: add #include <Array.au3> #include <String.au3> to the MailSlot UDF.

Second:

Func _MailSlotWrite($sMailSlotName, $vData, $iMode = 0, $iSwitch = " ")

    If IsArray($vData) Then;===If it's an array turn it to a string.
        $vData = _ArrayToString ( $vData )
        $vData = $iSwitch & $vData;===Add the switch to the data to be read.
    Else
        $vData = $iSwitch & $vData;===Add the switch to the data to be read.
    EndIf





    Local $aCall = DllCall("kernel32.dll", "ptr", "CreateFileW", _
            "wstr", $sMailSlotName, _
            "dword", 0x40000000, _ ; GENERIC_WRITE
            "dword", 1, _ ; FILE_SHARE_READ
            "ptr", 0, _
            "dword", 3, _ ; OPEN_EXISTING
            "dword", 0, _ ; SECURITY_ANONYMOUS
            "ptr", 0)

    If @error Or $aCall[0] = -1 Then
        Return SetError(1, 0, 0)
    EndIf



    Local $hMailSlotHandle = $aCall[0]

    Local $bData



    Switch $iMode

        Case 1
            $bData = StringToBinary($vData, 1)
        Case 2
            $bData = StringToBinary($vData, 4)
        Case Else
            $bData = $vData

    EndSwitch



    Local $iBufferSize = BinaryLen($bData)

    Local $tDataBuffer = DllStructCreate("byte[" & $iBufferSize & "]")
    DllStructSetData($tDataBuffer, 1, $bData)

    $aCall = DllCall("kernel32.dll", "int", "WriteFile", _
            "ptr", $hMailSlotHandle, _
            "ptr", DllStructGetPtr($tDataBuffer), _
            "dword", $iBufferSize, _
            "dword*", 0, _
            "ptr", 0)

    If @error Or Not $aCall[0] Then
        $aCall = DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hMailSlotHandle)
        If @error Or Not $aCall[0] Then
            Return SetError(4, 0, 0)
        EndIf

        Return SetError(2, 0, 0)
    EndIf



    Local $iOut = $aCall[4]

    $aCall = DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hMailSlotHandle)
    If @error Or Not $aCall[0] Then
        Return SetError(3, 0, $iOut)
    EndIf



    Return $iOut



EndFunc   ;==>_MailSlotWrite
Func _MailSlotRead($hMailSlot, $iSize, $iMode = 0)

    Local $Switch, $ReturnArray



    Local $tDataBuffer = DllStructCreate("byte[" & $iSize & "]")

    Local $aCall = DllCall("kernel32.dll", "int", "ReadFile", _
            "ptr", $hMailSlot, _
            "ptr", DllStructGetPtr($tDataBuffer), _
            "dword", $iSize, _
            "dword*", 0, _
            "ptr", 0)

    If @error Then
        Return SetError(1, 0, "")
    EndIf



    If Not $aCall[0] Then
        Local $aLastErrorCall = DllCall("kernel32.dll", "int", "GetLastError")
        If @error Then
            Return SetError(2, 0, "")
        EndIf

        If $aLastErrorCall[0] = 122 Then ; ERROR_INSUFFICIENT_BUFFER
            Return SetError(-1, 0, "")
        Else
            Return SetError(3, $aLastErrorCall[0], "")
        EndIf

    EndIf



    Local $vOut



    Switch $iMode

        Case 1
            $vOut = BinaryToString(DllStructGetData($tDataBuffer, 1))
        Case 2
            $vOut = BinaryToString(DllStructGetData($tDataBuffer, 1), 4)
        Case Else
            $vOut = DllStructGetData($tDataBuffer, 1)
    EndSwitch





    ;===Seporate the data and the switch and put them in an array to return
    $Switch = StringLeft($vOut, 1)
    $vOut = StringTrimLeft($vOut, 1);===Remove the first number in the string because it is the switch
    If StringInStr($vOut, "|") Then $vOut = _StringExplode($vOut, "|");===If pipes are detected it was sent as an array, so turn it back to an array
    Local $ReturnArray[2] = [$Switch, $vOut]


    Return SetError(0, $aCall[4], $ReturnArray)

EndFunc   ;==>_MailSlotRead

And last, the new parameter for writing. The last parameter will be the switch. I set it up to be a single integer because I don't think I'll need more than 9 switches for my needs and wanted to keep it simple, but of course adaptations can be made.

_MailSlotWrite($sMailSlotName, $sDataToSend, 0, 5)

I've done basic tests and everything seems to work for me so far.

Link to comment
Share on other sites

Champak,

Personally I use MailSlot. Looking at your list:

  1. Just pass a suitable string to the other function to run a function when received
  2. I believe it is limited to strings, but they can easily be recast to other datatypes on arrival
  3. See above
  4. Very easy to set up.

I have never had any problems with it and would recommend it highly.

M23

This thread is very similar to a recent problem I have been working on. It ultimately led me to the answer I was seeking. Particularly this post by Melba23. Thank you!

I thought I would elaborate that when passing a handle (to a window for example) you have to "recast" it back to a handle using the HWnd($handle)  function. Because when it is passed it becomes the string representation of the handle (seen as a hex number at the bottom of the window tab in the AutoIt Window Info tool), which is not a usable handle.

Edited by MagnumXL
Added link
Link to comment
Share on other sites

First, I figured out how to pass multi-D arrays by finding this and adapting it a little...I don't know if this is a part of the problem I'm having now or it's the recasting thing.

Local $aArray=StringSplit($str ,"|" & @CR)
    Local $iFilas=StringSplit($str,@CR)
    Local $iCol=StringSplit($iFilas[1],"|")[0]
    $iFilas=$iFilas[0]
    Local $aArray2D[$iFilas][$iCol]
    Local $i=0
    For $f= 0 to $iFilas-1
        For $c=0 to $iCol-1
            $aArray2D[$f][$c]=$aArray[$i+$c+1]
        Next
        $i+=$iCol

    Next

    If UBound($aArray2D) < 2 Then $aArray2D = _StringExplode($str, "|");Test if it's one column, if it is just explode the original variable so it's a 1d array

    Return $aArray2D

So my problem is once I've passed the needed arrays from App 'A' to App 'B', App 'B' doesn't read them the same anymore.

Ex: While reading control functions, I have to put Int() in front of the array index,

So instead of simply doing:

ControlGetText($AppTitle_Traffic, "", $TRAFFIC_ARRAY[8][1])

I have to do:

ControlGetText($AppTitle_Traffic, "", Int($TRAFFIC_ARRAY[8][1]))

That's not a big issue I guess, although I would prefer not to do that. My real issue is when I'm trying to read out "words" and do an evaluation/comparison it just wont work no matter what I try...even trying to put it into a variable.

Ex: This doesn't work:

If $NAV_OPTIONS_ARRAY[3][0] = "All" Then

Now if I put $NAV_OPTIONS_ARRAY[3][0] in a MsgBox in App 'B' I see "All" in it as I should. I've stripped white space as well and nothing. How do I get App 'B' to see the actual value? How do I recast a 'word'?

 

Thanks.

Link to comment
Share on other sites

  • Moderators

Champak,

How do I recast a 'word'?

String should do the trick

Try

If String($NAV_OPTIONS_ARRAY[3][0]) = "All" Then

or force the string comparison using the == operator:

If $NAV_OPTIONS_ARRAY[3][0] == "All" Then

If not, then we will need to look at how you are converting and then reconverting the array.

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

I tried the string already and it didn't work, I just  tried the operator and that didn't either. Here's all that I have tried.

String($NAV_OPTIONS_ARRAY[3][0]) = "All"

String($NAV_OPTIONS_ARRAY[3][0]) == "All"

$NAV_OPTIONS_ARRAY[3][0] == "All"

$NAV_OPTIONS_ARRAY[3][0] = "All"

$rrr = $NAV_OPTIONS_ARRAY[3][0]
StringStripCR($rrr) == "All"

$rrr = $NAV_OPTIONS_ARRAY[3][0]
StringStripCR($rrr) = "All"

So I guess it has something to do with passing the array, but I can't figure it. I'm converting to a string using _ArrayToString(), then back to an array as stated in the previous post. Then in App 'B' I simply use $NAV_OPTIONS_ARRAY = $sData[1] ($sData[1] being how the array is returned) to share it in the app ($NAV_OPTIONS_ARRAY is already declared Global).

Link to comment
Share on other sites

What is this piece of code supposed to be doing?

StringStripCR($rrr) == "All"

Or this:

String($NAV_OPTIONS_ARRAY[3][0]) = "All"

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

If you honestly want help with your code then you need to post your code. Don't post nonsense like this, because you're not giving us what you're actually using and that tends to make those trying to help you a bit cranky.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...