????? ??????? ??????? ??????? ?? ?????? 32-?? Visual Basic ???????

?????? ????????? ?????? ?????????
???? ???????: 177696 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ????? Visual Basic ????????? ???? ???? ??? ?????? ???? ?? ???????. ??? ????? "????? ????? ????" ??? Windows 2000 ?? Windows NT; ??? ???? ????? ????? ?? ?? ????? ??? ??????? ??? ?? ?? ???? ????? 32-??.

???? ??? ??????? ????? ??????/?????? ???????? "?????? ??????? ???????" ?? Visual Basic.

??????? ????

?? ??? ??????? ???? ????? ????? NamedPipe ?? ?????? ?? ???? ????? ??????? ?????? ??????? ??????.

???? ??? ??????? ?????? ???? ????? ????? ????:
  1. ????? ??? ???? ???? ??????? ?????? ??????? ???? (?????? "?????? ??????? ???????" ?? ????? ?? ???? ????? ??? ???? ???? ?? ??????? Access ?????? ????? (DACL) ????? ??? ??? ????????? ???????? ??).
  2. ????? ????? ????? ????.
  3. ??????? ConnectNamedPipe ???? ??? ??? ????.
  4. ??????? ?/ReadFile ?? WriteFile ??? ??????? ??? ???????.
  5. ??????? DisconnectNamedPipe ??? ???????? ?? ??????? ??????? ????? ???????.
  6. ??? CloseHandle ??? ????? ????? ???? ?? ????? ??? ?????? 4.
???? ???? ????? ??????? "?????? ??????? ???????" ?? ???? "?????? ??????? ???????":
  1. ??????? CreateFile ?????? ??? ???? ??? "?????? ??????? ???????".
  2. ??????? ?/ReadFile ?? WriteFile ??? ??????? ??? ???????.
  3. ??????? CloseHandle ??? filehandle ??????? ?? CreateFile.
????? ?? ???? ?? ??????? CallNamedPipe ????? ?????? ???? ????? ??? ???????. CallNamedPipe ???? ??????? ? ???? ???? ? ???? ??? ? ?? ????? ????? ???????. ???? ?? ???? ?????? ?????.

???? ??????? ?????? ????? ????? "???? ?????? ??????? ???????" ????. ???? ???? ??? ??? ?????? rudimentary ?? ??????? ???????? ?????? ???? ?? ??????? ?? ????? ???????. ??? ?? ???? ?????? ??? ??? ??????? API ????? ???? ????? ?? ?????? ???? ?????.

???? ?????? ??????? ???????

  1. ????? ????? ????. ??? ????? Form1 ???? ???????.
  2. ????? ????????? ???????? ??????? ??? ???????:
       Option Explicit
       Private Const szPipeName = "\\.\pipe\bigtest"
       Private Const BUFFSIZE = 20000
       Private BigBuffer(BUFFSIZE) As Byte, pSD As Long
       Private sa As SECURITY_ATTRIBUTES
       Private hPipe As Long
    
       Private Sub Form_Click()
          Dim i As Long, dwOpenMode As Long, dwPipeMode As Long
          Dim res As Long, nCount As Long, cbnCount As Long
          For i = 0 To BUFFSIZE - 1       'Fill an array of numbers
             BigBuffer(i) = i Mod 256
          Next i
    
          'Create the NULL security token for the pipe
          pSD = GlobalAlloc(GPTR, SECURITY_DESCRIPTOR_MIN_LENGTH)
          res = InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)
          res = SetSecurityDescriptorDacl(pSD, -1, 0, 0)
          sa.nLength = LenB(sa)
          sa.lpSecurityDescriptor = pSD
          sa.bInheritHandle = True
    
          'Create the Named Pipe
          dwOpenMode = PIPE_ACCESS_DUPLEX Or FILE_FLAG_WRITE_THROUGH
          dwPipeMode = PIPE_WAIT Or PIPE_TYPE_MESSAGE Or PIPE_READMODE_MESSAGE
          hPipe = CreateNamedPipe(szPipeName, dwOpenMode, dwPipeMode, _
                                  10, 10000, 2000, 10000, sa)
    
          Do  'Wait for a connection, block until a client connects
             res = ConnectNamedPipe(hPipe, ByVal 0)
    
             'Read/Write data over the pipe
             cbnCount = 4
    
             res = ReadFile(hPipe, nCount, LenB(nCount), cbnCount, ByVal 0)
    
             If nCount <> 0 Then
    
                If nCount > BUFFSIZE Then 'Client requested nCount bytes
                   nCount = BUFFSIZE      'but only send up to 20000 bytes
                End If
                'Write the number of bytes requested
                res = WriteFile(hPipe, BigBuffer(0), nCount, cbnCount, ByVal 0)
                'Make sure the write is finished
                res = FlushFileBuffers(hPipe)
             End If
    
             'Disconnect the NamedPipe
             res = DisconnectNamedPipe(hPipe)
          Loop Until nCount = 0
    
          'Close the pipe handle
          CloseHandle hPipe
          GlobalFree (pSD)
          End
       End Sub
    					
  3. ????? ???? ????? ????? ?????? ????????? ???????:
       Option Explicit
    
       Public Const FILE_ATTRIBUTE_NORMAL = &H80
       Public Const FILE_FLAG_NO_BUFFERING = &H20000000
       Public Const FILE_FLAG_WRITE_THROUGH = &H80000000
    
       Public Const PIPE_ACCESS_DUPLEX = &H3
       Public Const PIPE_READMODE_MESSAGE = &H2
       Public Const PIPE_TYPE_MESSAGE = &H4
       Public Const PIPE_WAIT = &H0
    
       Public Const INVALID_HANDLE_VALUE = -1
    
       Public Const SECURITY_DESCRIPTOR_MIN_LENGTH = (20)
       Public Const SECURITY_DESCRIPTOR_REVISION = (1)
    
       Type SECURITY_ATTRIBUTES
               nLength As Long
               lpSecurityDescriptor As Long
               bInheritHandle As Long
       End Type
    
       Public Const GMEM_FIXED = &H0
       Public Const GMEM_ZEROINIT = &H40
       Public Const GPTR = (GMEM_FIXED Or GMEM_ZEROINIT)
    
       Declare Function GlobalAlloc Lib "kernel32" ( _
          ByVal wFlags As Long, ByVal dwBytes As Long) As Long
       Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
       Declare Function CreateNamedPipe Lib "kernel32" Alias _
          "CreateNamedPipeA" ( _
          ByVal lpName As String, _
          ByVal dwOpenMode As Long, _
          ByVal dwPipeMode As Long, _
          ByVal nMaxInstances As Long, _
          ByVal nOutBufferSize As Long, _
          ByVal nInBufferSize As Long, _
          ByVal nDefaultTimeOut As Long, _
          lpSecurityAttributes As Any) As Long
    
       Declare Function InitializeSecurityDescriptor Lib "advapi32.dll" ( _
          ByVal pSecurityDescriptor As Long, _
          ByVal dwRevision As Long) As Long
    
       Declare Function SetSecurityDescriptorDacl Lib "advapi32.dll" ( _
          ByVal pSecurityDescriptor As Long, _
          ByVal bDaclPresent As Long, _
          ByVal pDacl As Long, _
          ByVal bDaclDefaulted As Long) As Long
    
       Declare Function ConnectNamedPipe Lib "kernel32" ( _
          ByVal hNamedPipe As Long, _
          lpOverlapped As Any) As Long
    
       Declare Function DisconnectNamedPipe Lib "kernel32" ( _
          ByVal hNamedPipe As Long) As Long
    
       Declare Function WriteFile Lib "kernel32" ( _
          ByVal hFile As Long, _
          lpBuffer As Any, _
          ByVal nNumberOfBytesToWrite As Long, _
          lpNumberOfBytesWritten As Long, _
          lpOverlapped As Any) As Long
    
       Declare Function ReadFile Lib "kernel32" ( _
          ByVal hFile As Long, _
          lpBuffer As Any, _
          ByVal nNumberOfBytesToRead As Long, _
          lpNumberOfBytesRead As Long, _
          lpOverlapped As Any) As Long
    
       Declare Function FlushFileBuffers Lib "kernel32" ( _
          ByVal hFile As Long) As Long
    
       Declare Function CloseHandle Lib "kernel32" ( _
          ByVal hObject As Long) As Long
    					
  4. ?? ???? ???????.

???? ?????? ??????? ???????

  1. ????? ????? ????. ??? ????? Form1 ???? ???????.
  2. ????? ????? ?????? ??????? ????????:
       Type             Name               Caption/Default Value
       ----             ----               ---------------------
       TextBox          cbBytes            500
       CommandButton    cmdCallNamedPipe   Call Named Pipe
       TextBox          txtReceive
    					
  3. ????? ????????? ???????? ??????? ??? ???????:
       Option Explicit
       Private Const szPipeName = "\\.\pipe\bigtest", BUFFSIZE = 20000
       Private Declare Function CallNamedPipe Lib "kernel32" Alias _
          "CallNamedPipeA" ( _
          ByVal lpNamedPipeName As String, _
          lpInBuffer As Any, _
          ByVal nInBufferSize As Long, _
          lpOutBuffer As Any, _
          ByVal nOutBufferSize As Long, _
          lpBytesRead As Long, _
          ByVal nTimeOut As Long) As Long
    
       Private Sub cmdCallNamedPipe_Click()
          Dim res As Long, myStr As String, i As Long, cbRead As Long
          Dim numBytes As Long, bArray() As Byte, temp As String
    
          numBytes = cbBytes.Text
          If cbBytes.Text < 0 Then
             MsgBox "Value must be at least 0.", vbOKOnly
             Exit Sub
          End If
          If numBytes > BUFFSIZE Then
             numBytes = BUFFSIZE
          End If
          ReDim bArray(numBytes)  'Build the return buffer
    
          'Call CallNamedPipe to do the transaction all at once
          res = CallNamedPipe(szPipeName, numBytes, LenB(numBytes), _
             bArray(0), numBytes, _
             cbRead, 30000) 'Wait up to 30 seconds for a response
    
          If res > 0 Then
             temp = Format(bArray(0), " 000")
             For i = 1 To cbRead - 1
                If (i Mod 16) = 0 Then temp = temp & vbCrLf
                temp = temp & " " & Format(bArray(i), "000")
             Next i
             txtReceive.Text = temp
          Else
             MsgBox "Error number " & Err.LastDllError & _
                    " attempting to call CallNamedPipe.", vbOKOnly
          End If
       End Sub
    
    					
  4. ???? ??? ??? ??? ?????? ??? ??????? ??? ???? ??? ??? ??? ???? ?????? ????? ??? ????? '. ' ?? szPipeName ????? ??? ??? ???? ??????.
  5. ?? ???? ???????. ??????? ???????? ???????? ????? ????? ??? ????? ?????? ?? ???? ??? ?? ???? ??? ???????. ????? ?????? ???? ???? ?????? ?? ???? ???? ???? ???? ?????? ??????? ?????? ???????. ?? ??? ????? ????? ???? ????? ??? ?????? ?? "?????? ???? ???????." ??? ??? ?????? ????? ?????? 500 ??? ?????? ???? ??????? ?? 500 ???? ?? ????????. ????? ????? ?????? ?? ???? ???? cbBytes ?? 0 ??? 20000 ????. ?????? ?????? ?????? ?????? 0 (???) ?? ??????. ?? ????? ?????? ??? 233 (ERROR_PIPE_NOT_CONNECTED) ???? ???? ????.

    ?? ????? ????????? ?/????? ????? IO ?? ????? ???? "??????" ??????? ??? ??? ??????? ?? ??????? ???????? IO ??????. ????? ?????? ??? ???? ?? ????????? ??? ??? ????????? ?? Microsoft Platform SDK.

?????

???? ??? ?????? ??????? InterProcess (IPC) ?? Windows 2000 ? Windows NT ? Windows 95 ???? ?????? ??????? ?? ?????? ??????? ??? ???????? ??? ?????? ??????. ?????? ??? ????? ????? ?????? IPC ???????? ?? ?? ???? ????? ?????? ?????? ??????? ??????? ?? "????? ??????? ?? Microsoft:
95900: ????? interprocess ??? Win32s ? Windows 95 ?? Windows NT

???????

???? ???????: 177696 - ????? ??? ??????: 24/????/1428 - ??????: 2.4
????? ???
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 4.0 Enterprise Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Windows NT 4.0
  • Microsoft Windows NT 3.51 Service Pack 5
  • Microsoft Windows NT 4.0
  • Microsoft Windows 98 Standard Edition
  • Microsoft Win32 ????? ????? ???????
  • the operating system: Microsoft Windows 2000
  • Microsoft Windows 95
  • Microsoft Windows Millennium Edition
????? ??????: 
kbmt kbapi kbhowto KB177696 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????177696

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com