home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples5 / ch14 / pipesrc.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  2.3 KB  |  78 lines

  1. VERSION 5.00
  2. Begin VB.Form frmPipeSource 
  3.    Caption         =   "Pipe Source"
  4.    ClientHeight    =   2205
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1515
  7.    ClientWidth     =   3780
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   2205
  11.    ScaleWidth      =   3780
  12.    Begin VB.TextBox txtSrc 
  13.       Height          =   1215
  14.       Left            =   180
  15.       TabIndex        =   0
  16.       Top             =   720
  17.       Width           =   3315
  18.    End
  19.    Begin VB.Label Label1 
  20.       Caption         =   "Type into the text box:"
  21.       Height          =   255
  22.       Left            =   180
  23.       TabIndex        =   1
  24.       Top             =   240
  25.       Width           =   3375
  26.    End
  27. Attribute VB_Name = "frmPipeSource"
  28. Attribute VB_GlobalNameSpace = False
  29. Attribute VB_Creatable = False
  30. Attribute VB_PredeclaredId = True
  31. Attribute VB_Exposed = False
  32. Option Explicit
  33. ' Copyright 
  34.  1997 by Desaware Inc. All Rights Reserved
  35. Dim destdir$
  36. Dim hPipeRead&
  37. Dim hPipeWrite&
  38. Private Sub Form_Load()
  39.     Dim si As STARTUPINFO
  40.     Dim pi As PROCESS_INFORMATION
  41.     Dim sa As SECURITY_ATTRIBUTES
  42.     Dim res&
  43.     Dim holdstd&
  44.     destdir$ = InputBox$("Enter directory containing PipeDest.exe", , "d:\zdbook3\source\ch14\")
  45.     sa.nLength = Len(sa)
  46.     sa.bInheritHandle = True
  47.     si.cb = Len(si)
  48.     res = CreatePipe(hPipeRead, hPipeWrite, sa, 0)
  49.     If res = 0 Then
  50.         MsgBox "Can't create the pipe"
  51.         Exit Sub
  52.     End If
  53.     Call SetStdHandle(STD_INPUT_HANDLE, hPipeRead)
  54.     ' The child process inherits the handle
  55.     res = CreateProcess(destdir & "PipeDest.exe", vbNullString, sa, sa, True, NORMAL_PRIORITY_CLASS, ByVal 0&, vbNullString, si, pi)
  56.     If res = 0 Then
  57.         MsgBox "Can't create process"
  58.         Unload Me
  59.         Exit Sub
  60.     End If
  61.     ' Always close the process handles
  62.     Call CloseHandle(pi.hProcess)
  63.     Call CloseHandle(pi.hThread)
  64. End Sub
  65. Private Sub Form_Unload(Cancel As Integer)
  66.     If hPipeWrite <> 0 Then
  67.         Call CloseHandle(hPipeWrite)
  68.     End If
  69. End Sub
  70. Private Sub txtSrc_KeyPress(KeyAscii As Integer)
  71.     Dim char As Byte
  72.     Dim res&
  73.     char = KeyAscii
  74.     Dim written&
  75.     res = WriteFile(hPipeWrite, char, 1, written, 0)
  76.     KeyAscii = 0
  77. End Sub
  78.