Jump to content

problem sending Window Handle via pipe


Go to solution Solved by jdelaney,

Recommended Posts

Hi

According to the example in the help of the ConsoleRead() command, I can send a strings using "pipes" from one process to another.

well, I have think to send an window handler "hwnd" from one autoit program, to another autoit compiled program, so that the receiving program can handle the same window by directly using the hwnd handler. But unfortunately my tests have not worked:

here is my simple test:

From the main script I send the window handler of the target window:

#include <ie.au3>

$oIE = _IECreate ("http://www.google.com")

; it return the "hwnd" of the browser window
$sHWnd = String(_IEPropertyGet($oIE, "hwnd"))

; I send the "Handler to the other program
Run(@ComSpec & " /c Echo " & $sHWnd & "| ConsoleRead.exe")

And this is the program that receive the handle

(modified from the example in the help of the ConsoleRead())

; Compile this script to "ConsoleRead.exe".
; Open a command prompt to the directory where ConsoleRead.exe resides.
; Type the following on the command line:
;   echo Hello! | ConsoleRead.exe
;
; When invoked in a console window, the above command echos the text "Hello!"
; but instead of dispalying it, the | tells the console to pipe it to the STDIN stream
; of the ConsoleRead.exe process.

#include <IE.au3>

If Not @Compiled Then
    MsgBox(0, "", "This script must be compiled in order to properly demonstrate it's functionality.")
    Exit -1
EndIf

Local $data
While True
    $data &= ConsoleRead()
    If @error Then ExitLoop
    Sleep(25)
WEnd

MsgBox(0, "", "Received: " & @CRLF & @CRLF & $data)

$oIE2 = _IEAttach(HWnd($data),"HWND")
$oIE2.navigate("http://www.autoitscript.com/")

When I run the main script, the handler is sent to the consoleread.exe that correctly opens the msgbox (line 33) showing the correct handle,

but then I get this -> Error: Variable must be of type 'Object".

What am I doing wrong?

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • Solution

Pass it as a param to the script instead...

then you can convert to hwnd, just like you are doing hwnd()

helpfile:  Command Line Parameters

Shows how to send, and then read the params

Run("ConsoleRead.exe " & $sHWnd) ; note the trailing space after .exe

then, in consoleread.exe...

$data = $CmdLine[1] ; of course, it's better to loop through the $CmdLine array, but this is just the simplest sample

$hwnd = hwnd($data)

Edited by jdelaney
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

thank You (again) jdelaney

modified my script as you suggest and now works perfectly.

main script:

#include <IE.au3>
$oIE = _IECreate ("http://www.google.com")

; it return the "hwnd" of the browser window
$sHWnd = String(_IEPropertyGet($oIE, "hwnd"))

; I send the "Handler to the other program
Run("ConsoleRead.exe " & $sHWnd) ; note the trailing space after .exe

receiver (consoleread.exe)

#include <IE.au3>
$data = $CmdLine[1]
$oIE2 = _IEAttach(HWnd($data),"HWND")
$oIE2.navigate("http://www.autoitscript.com")

simpler and better!

I will use this technic to solve the problem in my >previous topic
I will do one general-purpose "external" subroutine to click "problematic" links  by sending to it with parameters the window hwnd and the link reference to be clicked. (what kind of variables can be passed via parameters?
Also objects like link reference?)

P.S.
(why doesn't it works with pipe?)

bye and thanks

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Oh, and one of my sig links includes a function to get an HTML dom object by it's XPATH.  If you add that into your called script, then you would be able to pass the hwnd to the IE browser, and the xpath to what you want to click...then use the function to get the dom object, and click...then you can re-use the script to click on any object 

Or, if there is an easy way to grab the object, like an id or name, you can pass through cmd the function to call, and the value of the id/name...Then you can use the Call(), and use the function string as the first param...check out the rest through helpfile

Edited by jdelaney
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

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