Results 1 to 3 of 3

Thread: [RESOLVED] [02/03] Help me out with NamedPipes !

Threaded View

  1. #1

    Thread Starter
    Lively Member Xcoder's Avatar
    Join Date
    Jan 2004
    Posts
    120

    [RESOLVED] [02/03] Help me out with NamedPipes !

    Vbfers,

    I have been trying to make this little app send strings with no avail. Its the VB.NET NamedPipes example from Microsoft:

    http://support.microsoft.com/kb/871044/en-us

    Its a Server-Client type of communication between processes which is exactly what I need. I want to communicate between two VB.NET apps which I control. I know another possible workaround could be using TCP sockets and I will check it afterwards.

    But just to keep on digging on this subject, on the server side it uses the ReadFile API function to receive the data from the pipe it opens. Here is the definition:

    Code:
    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
    Declares lpBuffer as Integer, and I have tried with byte arrays and string builders and I can't make it work.

    It gets to ConnectNamedPipe and awaits for a connection, it then performs the reading, byteCount has the received data.

    Code:
       'It connects here
       res = ConnectNamedPipe(hPipe, 0)
       'Read the data sent by the client over the pipe
       cbnCount = 4
       res = ReadFile(hPipe, byteCount, Len(byteCount), cbnCount, 0)

    On the client side it uses the CallNamedPipe function to send and receive info from the server.

    Code:
    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
    Code:
     res = CallNamedPipe(pipeName, numBytes, Len(numBytes), bArray(0), numBytes, cbRead, 30000)
    Again, it uses lpInBuffer to send an integer, and I have also tried changing this to byte arrays, string builders and objects. But it just receives useless garbage.

    Now, another issue that puzzles me is that If you run the app as posted on MSDN, the server sends back a byte array once the client has established a connection, but the receiving byte array is just not what the server sent, I find this odd, perhaps is part of the problem.

    Help me out VBF!

    XC
    Last edited by Xcoder; Mar 6th, 2008 at 09:53 AM.
    Last edited by Xcoder : 09-10-2001 at 12:45 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width