????? ??????? ??????? ??????? ??????? ????????? interprocess ?? Visual Basic.NET ?? ?? Visual Basic 2005

?????? ????????? ?????? ?????????
???? ???????: 871044 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

????? ??? ??????? ???? How to ??????? ??????? ??????? ??????? ?? Microsoft Visual Basic.NET ?? ?? Microsoft Visual Basic 2005 ????????? interprocess. ????? ??? ??????? ????? ????????? ?????? ???? ???? ????? ?????? / ?????? ???????? ????? ????? ???? ?? Visual Basic.NET ?? ?? Visual Basic 2005. ??????? ??? ??????? interprocess ?????? ????? ???? ????? ????? ???? ??????? ????? ????? ????. ??? ????? ??????? ??? ????? ??????? ???????? ???????:
  • ????? ????? ????? ????.
  • ??? ????? ?????? ???????? ?????? ConnectNamedPipe ??? ??? ????.
  • ??????? ????? ???????? ?????? CallNamedPipe.
  • ??????? ???? ReadFile ?? ?????? WriteFile ??????? ??? ????? ???????.
  • ??????? ???? DisconnectNamedPipe ??? ?????? ??????? ??????? ????? ???????.
  • ??????? ???? CloseHandle ??? ????? ??????? ?????? ??? ????? ???? ??? ????? ???????.

INTRODUCTION

????? ????? ???? ?? ????? ????? ?????? ???? ?? ????? ????????? ??? ???? ????? ???????? ????? ???? ?? ????. ????? ?????? ??????? ??????? ??????? ??? ????? ??????? ??? ???????? ??? ??? ????????? ?? ??? ???????? ??? ????? ??????? ?????? ??? ???? ?????. ????? ???? ????? ??????? ?????? " " ???? ??? ????? ???? ????? ????? ????, ? ??????? " ???? ???? ??????? " ???? ??? ????? ??? ??? ???? ???? ????? ????? ????.

????? ??????? Microsoft Visual Basic.NET ?? Microsoft Visual Basic 2005 ?????? ??????? ???? ??? ?????? ???? ???????? ??????? ??????? ???????. ????? ??? ??????? ???? ??????? ?????? ?????? ????? ????? ???? ??????? ??? ????????? Visual Basic.NET ?? Visual Basic Windows 2005.

?????????

????? ??? ??????? ???? ???? ?? ??????? ???????? ???????:
  • ??????? Windows
  • ????? Visual Basic.NET
  • ??????? ??????? ???????
???? ??????? ??????? ???????? ??????? ??????? ????????? ?? ???? ??????, ? ???? ??????? ???? ???????:
  • Microsoft Visual Studio.NET ?? Microsoft Visual Studio 2005
  • Microsoft.NET Framework

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

??? ????? ???? ????? ????? ????, ? ?? ??????? ?? ?????? ??? ???????? ???? ??? ???????:
  1. ????? ????? ????? ????.
  2. ??????? ???? ConnectNamedPipe ???? ?????? ??? ??? ????.
  3. ??????? ???? ReadFile ?? ?????? WriteFile ??????? ??? ????? ???????.
  4. ??????? ???? DisconnectNamedPipe ??? ?????? ??????? ??????? ????? ???????.
  5. ??????? ???? CloseHandle ??? ????? ??????? ??????.

????? ????? ?? ????? ????? Windows ???? ???? ???? ????? ????? ????

?????? ????? ?? ????? ????? Windows ???? ???? ????? ??????? ???????? Visual Basic.NET ?? 2005 Visual Basic " ? ???? ??? ???????:
  1. ???? ????? Microsoft Visual Studio.NET ?? Microsoft Visual Studio 2005.
  2. ?? ?? ??????? ???? ??? ??? ???? , ????? Project .
  3. ??? ????? Project , ???? ??? ?????? Visual Basic " ? ??? ?? ???? ??? ????? Windows ??? ????? .

    ?????? ?? Visual Studio ?? 2005 ??? Visual Basic ??? ????? Project .
  4. ?? ?????? ????? , ???? MyServerApp? ??? ?? ???? ??? ????? . ?????????? ??? ????? ????? ???? ???? Form1.
  5. ????? ????? ????? ???? ??? ??????? Form1.
  6. ?? ??????? ???? ???? ??? ???? ??????? .
  7. ?? ?????? ??????? Text ?? ????? ???? ????? ??? ????? ???????:
    ?? ??? ??????????? ??? ??????
    ???????
    Button1????? ????? ????? ????
    Button2????? ?? ??? ??????? ??????
    Button3??? ????? ??????
  8. ????? ???? ???? ????? ??? ??????? Form1 . ??? ????? ???? ?????? Label1 ????? ??? ??????? Form1.

????? ???? ????????? ??? ???? ????? ?? ????? Windows

?????? ????????? ?????? ???????? ?????? ??????? interprocess ?????? ??????? ????? ??????? ??????, ???? ??????? ???????:
  1. ?? ???? Explorer? ???? ??? ?????? ?????? ??? MyServerApp ??? ??? ????? , ????? ????? ???? ????? ??.
  2. ?? ???? ?????? ????? ???? ????-MyServerApp , ???? ??? ??? .
  3. ?? ?????? ???????? ???????? ??????? ??? ?????? ??????? Module1.vb :
    Public Const FILE_ATTRIBUTE_NORMAL As Short = &H80S
    Public Const FILE_FLAG_NO_BUFFERING As Integer = &H20000000
    Public Const FILE_FLAG_WRITE_THROUGH As Integer = &H80000000
    
    Public Const PIPE_ACCESS_DUPLEX As Short = &H3S
    Public Const PIPE_READMODE_MESSAGE As Short = &H2S
    Public Const PIPE_TYPE_MESSAGE As Short = &H4S
    Public Const PIPE_WAIT As Short = &H0S
    
    Public Const INVALID_HANDLE_VALUE As Short = -1
    
    Declare Function CreateNamedPipe Lib "kernel32" Alias "CreateNamedPipeA" _
    (ByVal lpName As String, ByVal dwOpenMode As Integer, _
    ByVal dwPipeMode As Integer, ByVal nMaxInstances As Integer, _
    ByVal nOutBufferSize As Integer, ByVal nInBufferSize As Integer, _
    ByVal nDefaultTimeOut As Integer, ByVal lpSecurityAttributes As IntPtr _
    ) As Integer
    
    Declare Function ConnectNamedPipe Lib "kernel32" _
        (ByVal hNamedPipe As Integer, ByVal lpOverlapped As Integer) As Integer
    
    Declare Function DisconnectNamedPipe Lib "kernel32" _
        (ByVal hNamedPipe As Integer) As Integer
    
    Declare Function WriteFile Lib "kernel32" _
    (ByVal hFile As Integer, ByRef lpBuffer() As Byte, _
    ByVal nNumberOfBytesToWrite As Integer, ByRef lpNumberOfBytesWritten As Integer, _
    ByVal lpOverlapped As Integer _
    ) As Integer
    
    Declare Function ReadFile Lib "kernel32" _
    (ByVal hFile As Integer, ByRef lpBuffer As Integer, _
    ByVal nNumberOfBytesToRead As Integer, ByRef lpNumberOfBytesRead As Integer, _
    ByVal lpOverlapped As Integer _
    ) As Integer
    
    Declare Function FlushFileBuffers Lib "kernel32" _
        (ByVal hFile As Integer) As Integer
    
    Declare Function CloseHandle Lib "kernel32" _
        (ByVal hObject As Integer) As Integer
    

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

??? ????? ????? ????? ???? ?? ????? ??? ????????? ?? ??? ??????. ????? ???? ?????? ??? ??????? ????? ?? ????? ???????? ??? ????? ???????. ?????? ????? ???? ??????? ???????:
  1. ?? ???? Explorer? ???? ??? ?????? ?????? ??? Form1 " ? ??? ?? ???? ??? ??? .
  2. ?? ????? ????? " ????? " ??????? Form1 " ? ???? ????? ??????? ????? ????? ????? ???? ?? ?? ?? ??? ????????? ???????? ??????? ??? ????? Button1_Click :
    Dim openMode, pipeMode As Integer
    'Create the named pipe
    openMode = PIPE_ACCESS_DUPLEX Or FILE_FLAG_WRITE_THROUGH
    pipeMode = PIPE_WAIT Or PIPE_TYPE_MESSAGE Or PIPE_READMODE_MESSAGE
    hPipe = CreateNamedPipe(pipeName, openMode, pipeMode, 10, 10000, 2000, 10000, IntPtr.Zero)
    Label1.Text = "Created the named pipe and waiting for the clients."
    Button1.Visible = False
    Button2.Visible = True
    Button3.Visible = True
  3. ??? ????????? ???????? ??????? ??? ????? Button1_Click :
    Private Const pipeName As String = "\\.\pipe\MyPipe"
    Private Const BUFFSIZE As Short = 10000
    Private Buffer(BUFFSIZE) As Byte
    Private hPipe As Integer
  4. ?? ???? Explorer? ???? ????? ??????? ??? Form1.vb .
  5. ?? ????? ????? " ????? " ??????? Form1 " ? ???? ????? ??????? ?????? ????????? ?????? , ?? ?? ??? ????????? ???????? ??????? ??? ????? Button2_Click :
    Dim byteCount, i, res, cbnCount As Integer
    For i = 0 To BUFFSIZE - 1 'Fill an array of numbers
       Buffer(i) = i Mod 256
    Next i
    'Wait for a connection, block until a client connects
    Label1.Text = "Waiting for client connections"
    Me.Refresh()
    Do
       res = ConnectNamedPipe(hPipe, 0)
       'Read the data sent by the client over the pipe
       cbnCount = 4
       res = ReadFile(hPipe, byteCount, Len(byteCount), cbnCount, 0)
       If byteCount > BUFFSIZE Then 'Client requested for byteCount bytes
           byteCount = BUFFSIZE 'but only send up to 20000 bytes
       End If
       'Write the number of bytes requested by the client 
       res = WriteFile(hPipe, Buffer, byteCount, cbnCount, 0)
       res = FlushFileBuffers(hPipe)
       'Disconnect the named pipe.
       res = DisconnectNamedPipe(hPipe)
       'Loop until the client makes no more requests for data. 
    Loop Until byteCount = 0
    Label1.Text = "Read or Write completed"
    Button2.Visible = False
  6. ?? ????? ????? " ????? " ? ???? ????? ??????? Form1 " ? ?? ?? ??? ????????? ???????? ??????? ??? ????? Form1_Load :
    Button2.Visible = False
    Button3.Visible = False
  7. ?? ???? Explorer? ???? ????? ??????? ??? Form1.vb .
  8. ?? ????? ????? " ????? " ??????? Form1 " ? ???? ????? ??????? ??? ????? ?????? , ?? ?? ??? ????????? ???????? ??????? ??? ????? Button3_Click :
    Dim res As Integer
    'Close the pipe handle when the client makes no requests
    CloseHandle(hPipe)
    Label1.Text = "Disconnected the named pipe"
  9. ?? ??????? Build , ???? ??? ????? ???? .

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

?????? ???? ????? ????? ???? ???? ???? ?? ??????, ???? ??????? ???????:
  1. ??????? ???? CreateFile ?????? ???? ??? ????? ??????? ??????.
  2. ??????? ???? ReadFile ?? ?????? WriteFile ??????? ??? ????? ???????.
  3. ??????? ???? CloseHandle ??? ???? ?? ?????? ?? ?????? CreateFile .
????? ????? ??????? ????? ????? ????? ???? ??????? ???? / ????. ??? ???????? ????? ????? ???? ????? ????? ? ????? ????? ?? ????? ???? ????? ?????. ???? ??????? ???? ????????? ??? ??? ????? ????? ????? ??????? ?? ??????. ?????? ???? ??????? ?????? TransactNamedPipe ?? ?????? CallNamedPipe ?????? ???????? ????? ??????? ??????.

?? ??? ?????? ?????, ???? ?????? ?????? CallNamedPipe ??? ????? ???????? ?? ???????? ???? ??????? ????? ????? ???? ? ?? ????? ???????? ?? ????? ???????.

????? ????? ?? ????? ????? Windows ???? ???? ?? ???? ????? ????? ????

?????? ????? Visual Basic.NET ?? Windows 2005 Visual Basic ???? ?????? ?? ??????? ??? ?????? ????? ??????? ?????? ???? ??? ???????:
  1. ???? ????? Microsoft Visual Studio.NET ?? Microsoft Visual Studio 2005.
  2. ?? ?? ??????? ???? ??? ??? ???? , ????? Project .
  3. ??? ????? Project , ???? ??? ?????? Visual Basic " ? ??? ?? ???? ??? ????? Windows ??? ????? .

    ?????? ?? Visual Studio ?? 2005 ??? Visual Basic ??? ????? Project .
  4. ?? ?????? ????? , ???? MyClientApp? ??? ?? ???? ??? ????? . ?????????? ??? ????? ????? ???? ???? Form1.
  5. ????? ???? ???? ?? ??? ??????? Form1.
  6. ???? ??? ?????? ?????? ??? Button1 , ??? ?? ???? ??? ????? .
  7. ????? ??????? Text ?? ??????? ??????? .
  8. ????? ???? ???? ????? ??? ??????? Form1. ??? ????? ???? ?????? Label1 ????? ??? ??????? Form1 .
  9. ????? ??????? ???? ????? ?????? ????? Label1 ??? ??? .
  10. ????? ????? ???? TextBox ??? ??????? Form1.

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

??????? ??? ???? ????? ??????? ???????? ?????? CallNamedPipe . ???? ?????? ??? ????? ???????, ??? ??????? ??? ??????? ?? CallNamedPipe ???? ?? ???????? ????? ?? ????? ????? ???????. ?? ???? ??????? ?? ????? ?? ????? ????????, ?? ???? ??????? ???????:
  1. ?? ????? ????? " ????? " ? ???? ????? ??????? ??????? ??????? , ?? ?? ??? ????????? ???????? ??????? ??? ????? Button1_Click :
    Dim i, res, cbRead,numBytes As Integer
    Dim bArray() As Byte
    Dim temp As String
    
    numBytes = CInt(TextBox1.Text)
    If numBytes < 0 Then
        MessageBox.Show("Value must be at least 0.", MsgBoxStyle.OKOnly)
        Exit Sub
    End If
    If numBytes = 0 Then
        Label1.Visible = True
        Label1.Text = "The connection to the server is disconnected."
        Button1.Visible = False
        TextBox1.Visible = False
        TextBox2.Visible = False
    End If
    If numBytes > BUFFSIZE Then
        numBytes = BUFFSIZE
    End If
    
    ReDim bArray(numBytes) 'Create the return buffer
    'Call the CallNamedPipe function to do the transactions
     res = CallNamedPipe(pipeName, numBytes, Len(numBytes), bArray(0), numBytes, cbRead, 30000) 
    'Wait up to 30 seconds for a response
    'Format the data received, and then display the data in the text box
    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
        TextBox2.Text = temp
    Else
    MessageBox.Show("Error number " & Err.LastDllError & _
    "while trying to call the CallNamedPipe function.", MsgBoxStyle.OKOnly)
    End If
  2. ??? ????????? ???????? ??????? ??? ????? Button1_Click :
    Private Const pipeName As String = "\\.\pipe\MyPipe"
    Private Const BUFFSIZE As Integer = 10000
    Private hpipe As Integer
        
    Public Const INVALID_HANDLE_VALUE As Short = -1
    Public Declare Function CallNamedPipe Lib "kernel32" Alias "CallNamedPipeA" _
    (ByVal lpNamedPipeName As String, _
    ByRef lpInBuffer As Integer, _
    ByVal nInBufferSize As Integer, _
    ByRef lpOutBuffer As Byte, _
    ByVal nOutBufferSize As Integer, _
    ByRef lpBytesRead As Integer, ByVal nTimeOut As Integer) As Integer
  3. ?? ??????? Build , ???? ??? ????? ???? .

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

?????? ?? ??? ????????? ???????? ???? ??? ???????:
  1. ???? ????? ??????, ???? ??? ???? ?? ??????? ??? ??????? MyServerApp Debug .
  2. ?? ???????? Form1 ???? ??? " ????? ????? ????? ???? , ??? ?? ???? ??? ?????? ????????? ?????? . ??????? ??? ??? ???? ?? ????? ?????? ???????.
  3. ???? ????? ??????, ???? ??? ???? ?? ??????? ??? ??????? MyClientApp Debug .
  4. ?? ???????? Form1 ???? 10 ?? TextBox1 ???? ??? ?? ???? ??? ??????? ??????? . ????? ?????? ???? ????? ?????? ???? ?? ?????? ?? ?????? TextBox2 .
  5. ???? ????? ?????? ?? ??????? ???? 0 ?? TextBox1 ???? ?? ????? ??????, ??? ?? ???? ??? ??????? ??????? .
  6. ???? ????? ??????.
  7. ?????? ?? ??? ????? ????? ???? ????? ??????? ??????, ?????? ????? ??????, ???? ??? ??? ????? ?????? ??? ????? Form1 ?? ????? ??????.

?????

?????? ??? ???? ?? ?????????, ????? ????? ????? ??? Microsoft Developer Network (MSDN) ???????:
??????? ??????? ???????
http://msdn2.microsoft.com/en-us/library/aa365590.aspx
????????? ??? ??????? ??????? ???????
http://msdn2.microsoft.com/en-us/library/aa365789.aspx
????? ???????
http://msdn2.microsoft.com/en-us/library/aa365781.aspx

???????

???? ???????: 871044 - ????? ??? ??????: 21/?? ?????/1427 - ??????: 2.4
????? ???
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
????? ??????: 
kbvs2005swept kbvs2005applies kbserver kbpipes kbipc kbclient kbhowtomaster kbhowto KB871044 KbMtar kbmt
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????. ??? ?? ???? ??? ??????? ????? ?? ???????? ?? ??? ???????? ?????? ????? ????????? ??????? ???? ??? ???????
???? ??? ????? ??????? ?????? ??????????871044

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

 

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