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 / samples4 / ch14 / pipesrc.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  2.3 KB  |  79 lines

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