Sign in to follow this  
Followers 0
JohnBailey

Send Params to a running AU3

12 posts in this topic

Scenario: (Note: I will use GUIs in this scenario, because it is easier to discuss) I have two AU3 GUIs open that I've created (so I have complete control). I click a button in GUI-1. How do I send parameters defined in the button action to GUI-2 and have GUI-2 receive it?

The only idea I could come up with is a TCP connection. That seems cumbersome and really doesn't answer my question.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Scenario: (Note: I will use GUIs in this scenario, because it is easier to discuss) I have two AU3 GUIs open that I've created (so I have complete control). I click a button in GUI-1. How do I send parameters defined in the button action to GUI-2 and have GUI-2 receive it?

The only idea I could come up with is a TCP connection. That seems cumbersome and really doesn't answer my question.

If you're geeky enough with AutoIt, you can search the forum for in depth discussion of WM_COPYDATA.

For lower lifeforms like myself there's simply working on the controls: Using GUI Controls for interprocess comms

Keep in mind that the controls used don't have to be visible for that to work.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

If you're geeky enough with AutoIt, you can search the forum for in depth discussion of WM_COPYDATA.

For lower lifeforms like myself there's simply working on the controls: Using GUI Controls for interprocess comms

Keep in mind that the controls used don't have to be visible for that to work.

:)

Lower lifeforms nothing! ;) That's a really smart idea. I didn't even think of that, so if I'm a lower lifeform too then I'm lower than low ;) It's a really creative idea. I'm also going to look up WM_COPYDATA, because I'm curious like that and enjoy learning neat stuff (even if I can't use it usually I'm enlightened along the way).

thanks as always PsaltyDS!


A decision is a powerful thing

Share this post


Link to post
Share on other sites

PsaltyDS, I found the following two (a sender and receiver). However, I'm doing something wrong. I don't understand one part at all which I will point out in a moment. First I must show you the two scripts.

SENDER

;original by martin (http://www.autoitscript.com/forum/index.php?showtopic=50110&view=findpost&p=389386)

#include <misc.au3>

; Windows Definitions
Global Const $StructDef_COPYDATA = "ptr;dword;ptr"
Global Const $WM_COPYDATA = 0x4A

Global Const $STRUCTDEF_AU3MESSAGE = "char[256];int"
$TextToSend = "Something for us to shout about!"
;$CDString = DllStructCreate("char var1[256]");the array to hold the string we are sending
$CDString = DllStructCreate($STRUCTDEF_AU3MESSAGE);the array to hold the string we are sending

DllStructSetData($CDString,1,$TextToSend)
$pCDString = DllStructGetPtr($CDString);the pointer to the string

$vs_cds = DllStructCreate($StructDef_COPYDATA);create the message struct
DllStructSetData($vs_cds,"var1",0);0 here indicates to the receiving program that we are sending a string
DllStructSetData($vs_cds,"var2",StringLen($TextToSend) + 1);tell the receiver the length of the string
DllStructSetData($vs_cds,"var3",$pCDString);the pointer to the string
$pStruct = DllStructGetPtr($vs_cds)
_SendMessage(WinGetHandle("getMessage"),$WM_COPYDATA,0,$pStruct)

MsgBox(0,'Sender - Done','String sent')

$vs_cds = 0;free the struct
$CDString = 0;free the structoÝ÷ Ù´DBÛjëh×6;original by piccaso http://www.autoitscript.com/forum/index.php?showtopic=22598&hl=

; Windows Definitions
Global Const $StructDef_COPYDATA = "ptr;dword;ptr"
Global Const $WM_COPYDATA = 0x4A
Global Const $WM_CLOSE = 0x10
; The costum Struct (Must be the same in Sender and Recivcer)
Global Const $STRUCTDEF_AU3MESSAGE = "char[256];int"

; Create Reciver window
$hwmd_Reciver = GUICreate("getMessage")
; Register Windows Messages
GUIRegisterMsg($WM_COPYDATA, "_GUIRegisterMsgProc")
GUIRegisterMsg($WM_CLOSE, "_GUIRegisterMsgProc")
; Message Handler
Func _GUIRegisterMsgProc($hWnd, $MsgID, $WParam, $LParam)
    If $MsgID = $WM_COPYDATA Then
        ; We Recived a WM_COPYDATA Message
        ; $LParam = Poiter to a COPYDATA Struct
        $vs_cds = DllStructCreate($StructDef_COPYDATA, $LParam)
        ; Member No. 3 of COPYDATA Struct (PVOID lpData;) = Pointer to Costum Struct
        $vs_msg = DllStructCreate($STRUCTDEF_AU3MESSAGE, DllStructGetData($vs_cds, 3))
        ; Display what we have recived
        MsgBox(0, "Recver - Test String", DllStructGetData($vs_msg, 1))
        MsgBox(0, "Recver - Test Integer", DllStructGetData($vs_msg, 2))
    ElseIf $MsgID = $WM_CLOSE Then
        ; We Recived a WM_CLOSE Message
        Exit
    EndIf
EndFunc   ;==>_GUIRegisterMsgProc
; Keep it Runnig ...
While 1
    Sleep(250)
WEndoÝ÷ Ù´$È8ßÛJéeíë׫1ªí{zk-¡·¬zwbayÖ­jë"§jºÚÊ좻ljëh×6$CDString = DllStructCreate("char var1[256]");the array to hold the string we are sending
$vs_cds = DllStructCreate($StructDef_COPYDATA);create the message struct
DllStructSetData($vs_cds,"var1",0);0 here indicates to the receiving program that we are sending a string
DllStructSetData($vs_cds,"var2",StringLen($TextToSend) + 1);tell the receiver the length of the string
DllStructSetData($vs_cds,"var3",$pCDString);the pointer to the string
$pStruct = DllStructGetPtr($vs_cds)

I just don't understand DllStructSetData well enough (or barely at all) to know what to change to get these two to "read each other." They, and I could be wrong, seem to be shaking hands. What do I need to be looking at changing in the receiver or sender?


A decision is a powerful thing

Share this post


Link to post
Share on other sites

I recently made a UDF for this, based off PsaltyDS's idea. Check it out if you would like to. It's very simple, there's no messing with DLLS or whatever.


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites

PsaltyDS, I found the following two (a sender and receiver). However, I'm doing something wrong. I don't understand one part at all which I will point out in a moment. First I must show you the two scripts.

SENDER

$StructDef_COPYDATA = "ptr;dword;ptr"

$vs_cds = DllStructCreate($StructDef_COPYDATA) ;create the message struct
DllStructSetData($vs_cds,"var1",0) ;0 here indicates to the receiving program that we are sending a string
DllStructSetData($vs_cds,"var2",StringLen($TextToSend) + 1) ;tell the receiver the length of the string
DllStructSetData($vs_cds,"var3",$pCDString) ;the pointer to the string
$pStruct = DllStructGetPtr($vs_cds)oÝ÷ Øî²×hmºw^®ËZÐå+k¹ËRzÐÚµ¬W§¢è!¢¶Ú­érjÖ¥Ú$0«m¡ÈZ­¢­¶¬zÜ(¶®¢ÚÞi×r-êêºSìÒ¢é]+¢x,yé­¡·¬©"ZÛ«] ÞyÛhméh¢H§«©àx"Ø^­ç÷«¢»×«þX¬µ8ZK7ݩݬx!¢é]$Þ{h¶¥y¦-yÖ¢÷­+)¢Ëªê-xýz,·±¥êí~캷·Ü­#
'uêðêÞÊ ¢Ú®¢ÛÚ¯Z®¢Ûa®ê®¢ÛÚ¯z®¢×ë¢d¡¢é]m¶­m殶­sbb33cµ7G'V7DFVeô4õDDÒgV÷C·G#¶Gv÷&C·G"gV÷C° ¢b33c·g5ö6G2ÒFÆÅ7G'V7D7&VFRb33cµ7G'V7DFVeô4õDD¶7&VFRFRÖW76vR7G'V7@¤FÆÅ7G'V7E6WDFFb33c·g5ö6G2ÃóW&RæF6FW2FòFR&V6Vfær&öw&ÒFBvR&R6VæFær7G&æp¤FÆÅ7G'V7E6WDFFb33c·g5ö6G2ÃÅ7G&ætÆVâb33cµFWEFõ6VæB²·FVÆÂFR&V6VfW"FRÆVæwFöbFR7G&æp¤FÆÅ7G'V7E6WDFFb33c·g5ö6G2Ã"Âb33c·4E7G&ær·FRöçFW"FòFR7G&æp¢b33c·7G'V7BÒFÆÅ7G'V7DvWEG"b33c·g5ö6G2

Because you never assigned the names "var1" thru "var3" to those items, so they should be referenced by index number. Still, I could very easily be wrong on that...

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I'm no DLL expert for sure! But I wonder where you got "var1" thru "var3" from? Shouldn't that be:

$StructDef_COPYDATA = "ptr;dword;ptr"

$vs_cds = DllStructCreate($StructDef_COPYDATA) ;create the message struct
DllStructSetData($vs_cds,0,0) ;0 here indicates to the receiving program that we are sending a string
DllStructSetData($vs_cds,1,StringLen($TextToSend) + 1) ;tell the receiver the length of the string
DllStructSetData($vs_cds,2,$pCDString) ;the pointer to the string
$pStruct = DllStructGetPtr($vs_cds)

Because you never assigned the names "var1" thru "var3" to those items, so they should be referenced by index number. Still, I could very easily be wrong on that...

:)

What you wrote makes sense. The var1 thru var3 was already in the script per Martin. I'll try that (what you wrote)


A decision is a powerful thing

Share this post


Link to post
Share on other sites

PsaltyDS, I tried getting rid of the var1 thru var3 and replacing them with the numbers 1 thru 3, but that doesn't work either.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

this works!

SENDER

;original by martin (http://www.autoitscript.com/forum/index.php?showtopic=50110&view=findpost&p=389386)
;adjusted
#include <misc.au3>

; Windows Definitions
;Global Const $StructDef_COPYDATA = "ptr;dword;ptr"
Global Const $StructDef_COPYDATA = "dword var1;dword var2;ptr var3";I have changed piccaso's structure
Global Const $WM_COPYDATA = 0x4A

Global Const $STRUCTDEF_AU3MESSAGE = "char[256];int"
$TextToSend = "Something for us to shout about!"
$CDString = DllStructCreate("char var1[256]");the array to hold the string we are sending
;$CDString = DllStructCreate($STRUCTDEF_AU3MESSAGE);the array to hold the string we are sending


DllStructSetData($CDString,1,$TextToSend)
$pCDString = DllStructGetPtr($CDString);the pointer to the string

$vs_cds = DllStructCreate($StructDef_COPYDATA);create the message struct
DllStructSetData($vs_cds,"var1",0);0 here indicates to the receiving program that we are sending a string
DllStructSetData($vs_cds,"var2",StringLen($TextToSend) + 1);tell the receiver the length of the string
DllStructSetData($vs_cds,"var3",$pCDString);the pointer to the string
$pStruct = DllStructGetPtr($vs_cds)
_SendMessage(WinGetHandle("getMessage"),$WM_COPYDATA,0,$pStruct)

MsgBox(0,'Sender - Done','String sent')

$vs_cds = 0;free the struct
$CDString = 0;free the structoÝ÷ Ù´DBÛjëh×6;original by piccaso http://www.autoitscript.com/forum/index.php?showtopic=22598&hl=

; Windows Definitions
;Global Const $StructDef_COPYDATA = "ptr;dword;ptr"
Global Const $StructDef_COPYDATA = "dword var1;dword var2;ptr var3";I have changed piccaso's structure
Global Const $WM_COPYDATA = 0x4A
Global Const $WM_CLOSE = 0x10
; The costum Struct (Must be the same in Sender and Recivcer)
;Global Const $STRUCTDEF_AU3MESSAGE = "char[256];int"
Global Const $STRUCTDEF_AU3MESSAGE = "char var1[256]"

; Create Reciver window
$hwmd_Reciver = GUICreate("getMessage")
; Register Windows Messages
GUIRegisterMsg($WM_COPYDATA, "_GUIRegisterMsgProc")
GUIRegisterMsg($WM_CLOSE, "_GUIRegisterMsgProc")
; Message Handler
Func _GUIRegisterMsgProc($hWnd, $MsgID, $WParam, $LParam)
    If $MsgID = $WM_COPYDATA Then
        ; We Recived a WM_COPYDATA Message
        ; $LParam = Poiter to a COPYDATA Struct
        $vs_cds = DllStructCreate($StructDef_COPYDATA, $LParam)
        ; Member No. 3 of COPYDATA Struct (PVOID lpData;) = Pointer to Costum Struct
        $vs_msg = DllStructCreate($STRUCTDEF_AU3MESSAGE, DllStructGetData($vs_cds, 3))
        ; Display what we have recived
        MsgBox(0, "Recver - Test String", DllStructGetData($vs_msg, 1))
        MsgBox(0, "Recver - Test Integer", DllStructGetData($vs_msg, 2))
    ElseIf $MsgID = $WM_CLOSE Then
        ; We Recived a WM_CLOSE Message
        Exit
    EndIf
EndFunc   ;==>_GUIRegisterMsgProc
; Keep it Runnig ...
While 1
    Sleep(250)
WEnd

A decision is a powerful thing

Share this post


Link to post
Share on other sites

PsaltyDS, I tried getting rid of the var1 thru var3 and replacing them with the numbers 1 thru 3, but that doesn't work either.

That should be 0 to 2, not 1 to 3, I believe.

this works!

SENDER

Global Const $StructDef_COPYDATA = "dword var1;dword var2;ptr var3";I have changed piccaso's structure

;... 

DllStructSetData($vs_cds,"var1",0);0 here indicates to the receiving program that we are sending a string
DllStructSetData($vs_cds,"var2",StringLen($TextToSend) + 1);tell the receiver the length of the string
DllStructSetData($vs_cds,"var3",$pCDString);the pointer to the string
That makes sense, you named them var1 thru var3 and reference them by those names.

Glad you got it working.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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