Sign in to follow this  
Followers 0
Jay_M

Using named pipes

3 posts in this topic

All,

This is my first posting to this forum. I am attempting to develop an AutoIt script which can communicate with other applications via named pipes. I want to be able to create a server script which will create and be able to read and write to the pipe. I was able to write to a pipe, from autoIt, by opening a file with a pipe name such as $file = FileOpen("\\server-name\pipe\pipe-name", 2). However, I want to be able to create a pipe server and to have more control over the reading and writing such as timeout values, etc.

Share this post


Link to post
Share on other sites



Haven't done anything with it, but I made this while tinkering. Thanks to Valik for reading the MSDN page for CreateNamedPipe for me.

$ourDll = DllOpen(@SystemDir & "\kernel32.dll")
  
 ; WaitNamedPipe() works fine:
  $call = DllCall($ourDll, "int", "WaitNamedPipe", "str", "\\.\pipe\lsass", "int", 0)
  If @error = 1 Then
     MsgBox(0, "debug", "DllCall() failed...")
  Else
     If $call[0] Then
        MsgBox(0, "debug", "Found named pipe (lsass)!")
     Else
        MsgBox(0, "debug", "No such named pipe (lsass) visible...")
     EndIf
  EndIf
  
  $call = DllCall($ourDll, "int", "WaitNamedPipe", "str", "\\.\pipe\AutoIt3", "int", 0)
  If @error = 1 Then
     MsgBox(0, "debug", "DllCall() failed...")
  Else
     If $call[0] Then
        MsgBox(0, "debug", "Found named pipe (AutoIt3)!")
     Else
        MsgBox(0, "debug", "No such named pipe (AutoIt3) visible...")
     EndIf
  EndIf
  
 ; CreateNamedPipe proto:
 ;HANDLE CreateNamedPipe(
 ;  LPCTSTR lpName,
 ;  DWORD dwOpenMode,
 ;  DWORD dwPipeMode,
 ;  DWORD nMaxInstances,
 ;  DWORD nOutBufferSize,
 ;  DWORD nInBufferSize,
 ;  DWORD nDefaultTimeOut,
 ;  LPSECURITY_ATTRIBUTES lpSecurityAttributes );
 $call = DllCall($ourDll, "ptr", "CreateNamedPipe", "str", "\\.\pipe\AutoIt3", "int", 3, "int", 0, "int", 1, "int", 0, "int", 0, "int", 1, "ptr", 0)
 ;$call = DllCall($ourDll, "int", "GetLastError")
 ;MsgBox(0, "Debug", "Last Error:" & $call[0]); Returns ERROR_INVALID_PARAMETER (87) for me...
  If @error = 1 Then
     MsgBox(0, "debug", "DllCall() failed...")
  Else
     If $call[0] =  -1 Then
        MsgBox(0, "debug", "Couldn't create named pipe (AutoIt3)...")
     Else
        MsgBox(0, "debug", "Created named pipe (AutoIt3)!")
     EndIf
  EndIf
  
  $call2 = DllCall($ourDll, "int", "WaitNamedPipe", "str", "\\.\pipe\AutoIt3", "int", 0)
  If @error = 1 Then
     MsgBox(0, "debug", "DllCall() failed...")
  Else
     If $call2[0] Then
        MsgBox(0, "debug", "Found named pipe (AutoIt3)!")
     Else
        MsgBox(0, "debug", "No such named pipe (AutoIt3) visible...")
     EndIf
  EndIf

It's been months since I played with this, I'd be interested in any results that you get.


Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

DaveF,

Thanks for the sample code, it worked fine. I'm thinking about using this as a starting point to build an include library to provide pipe function calls.

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