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:
Declares lpBuffer as Integer, and I have tried with byte arrays and string builders and I can't make it work.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
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 IntegerAgain, 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.Code:res = CallNamedPipe(pipeName, numBytes, Len(numBytes), bArray(0), numBytes, cbRead, 30000)
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




Reply With Quote