Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/Windows Pipe
This example is the version from Fri, 26th Sep 2019.
Project "Windows Pipe.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control NameField Inherits TextField
ControlInstance NameField Inherits TextField
End Control
Control NameLabel Inherits Label
ControlInstance NameLabel Inherits Label
End Control
Control CreateButton Inherits PushButton
ControlInstance CreateButton Inherits PushButton
EventHandler Sub Action()
pipe = New WindowsPipeMBS
Const UseMessageMode = False
// pass false for byte mode, where you read just bytes
// pass true, where one write on one side, will result in a ReadAll on the other side.
// whether to allow all users on computer
Const AllowAllUsers = True
const BufferSize = 1024*1024
If pipe.CreatePipe(NameField.Text, UseMessageMode, BufferSize, AllowAllUsers) Then
EnableControls
Else
MsgBox "Failed to create pipe with error "+Str(pipe.LastError)
End If
End EventHandler
End Control
Control OpenButton Inherits PushButton
ControlInstance OpenButton Inherits PushButton
EventHandler Sub Action()
pipe = New WindowsPipeMBS
If pipe.OpenPipe(NameField.Text) Then
EnableControls
Else
MsgBox "Failed to open pipe with error "+Str(pipe.LastError)
End If
End EventHandler
End Control
Control ClosePipeButton Inherits PushButton
ControlInstance ClosePipeButton Inherits PushButton
EventHandler Sub Action()
ClosePipe
End EventHandler
End Control
Control SendButton Inherits PushButton
ControlInstance SendButton Inherits PushButton
EventHandler Sub Action()
SendMessage
End EventHandler
End Control
Control MessageField Inherits TextField
ControlInstance MessageField Inherits TextField
EventHandler Function KeyDown(Key As String) As Boolean
If Asc(key) = 13 Or Asc(key) = 3 Then
SendMessage
Return True
End If
End EventHandler
EventHandler Sub TextChange()
If Me.Enabled Then
SendButton.Enabled = Me.Text.Len > 0
End If
End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control InfoButton Inherits PushButton
ControlInstance InfoButton Inherits PushButton
EventHandler Sub Action()
If pipe <> Nil Then
Dim InputBufferSize As Integer = pipe.InputBufferSize
Dim OutputBufferSize As Integer = pipe.OutputBufferSize
Dim NamedPipeClientProcessId As Integer = pipe.NamedPipeClientProcessId
Dim NamedPipeClientSessionId As Integer = pipe.NamedPipeClientSessionId
Dim NamedPipeServerProcessId As Integer = pipe.NamedPipeServerProcessId
Dim NamedPipeServerSessionId As Integer = pipe.NamedPipeServerSessionId
Dim NamedPipeClientComputerName As String = pipe.NamedPipeClientComputerName
Dim lines() As String
lines.Append "Handle: "+Str(pipe.Handle)
lines.Append "InputBufferSize: "+Str(InputBufferSize)
lines.Append "OutputBufferSize: "+Str(OutputBufferSize)
lines.Append "NamedPipeClientProcessId: "+Str(NamedPipeClientProcessId)
lines.Append "NamedPipeClientSessionId: "+Str(NamedPipeClientSessionId)
lines.Append "NamedPipeServerProcessId: "+Str(NamedPipeServerProcessId)
lines.Append "NamedPipeServerSessionId: "+Str(NamedPipeServerSessionId)
lines.Append "NamedPipeClientComputerName: "+NamedPipeClientComputerName
lines.Append "IsServer: "+Str(pipe.IsServer)
MsgBox Join(lines,EndOfLine)
End If
End EventHandler
End Control
Sub ClosePipe()
pipe = Nil // closes
CreateButton.Enabled = True
ClosePipeButton.Enabled = False
SendButton.Enabled = False
InfoButton.Enabled = False
MessageField.Enabled = False
OpenButton.Enabled = True
CreateButton.Enabled = True
End Sub
Sub EnableControls()
CreateButton.Enabled = False
OpenButton.Enabled = False
ClosePipeButton.Enabled = True
SendButton.Enabled = True
InfoButton.Enabled = True
MessageField.Enabled = True
List.DeleteAllRows
AddHandler pipe.PipeBroken, WeakAddressOf PipeBroken
AddHandler pipe.DataAvailable, WeakAddressOf PipeDataAvailable
AddHandler pipe.Connected, WeakAddressOf PipeConnected
End Sub
Sub PipeBroken(pipe as WindowsPipeMBS)
// end of pipe
List.AddRow "Pipe broken."
ClosePipe
End Sub
Sub PipeConnected(pipe as WindowsPipeMBS)
List.AddRow "Connected"
End Sub
Sub PipeDataAvailable(pipe as WindowsPipeMBS, bytesAvailable as integer, MessageBytesAvailable as integer)
'Dim r As String = pipe.Read(BytesAvailable)
Dim r As String = pipe.ReadAll
Dim d As String = DefineEncoding(r, Encodings.UTF8)
List.AddRow d
End Sub
Sub SendMessage()
Dim d As String = ConvertEncoding(MessageField.Text, encodings.UTF8)
If d.Len > 0 Then
// in byte mode, this will be part of the data we read
// in message mode, we read two items
pipe.Write ">"
pipe.Write d
MessageField.Text = ""
End If
End Sub
Property pipe As WindowsPipeMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
See also:
The items on this page are in the following plugins: MBS Win Plugin.