PDA

View Full Version : Multithreaded named pipe problems



FrankTheFox
02-18-2007, 05:15 PM
Hi Folks,

first i want to show my problems before i post my code.

1. is it possible to use in MS Access VBA CreateThread(...)
my piece of code will terminate Access after thread termination.

2. I want to create a communication pipe between to processes (MS Access FrontEnd) on different computers.


Here is my code:


First server modul (it creates the pipe)

Option Compare Database
Option Explicit


Public Const PIPEBUFFSIZE As Long = 1024
Public Const PIPETIMEOUT As Long = 50 '50 ms
Public Const INVALID_HANDLE_VALUE As Long = -1

Public Const CREATE_SUSPENDED As Long = &H4
Public Const THREAD_PRIORITY_NORMAL As Long = &H0

Public Const PIPE_ACCESS_DUPLEX As Long = &H3
Public Const PIPE_ACCESS_INBOUND As Long = &H1
Public Const PIPE_ACCESS_OUTBOUND As Long = &H2
Public Const FILE_FLAG_WRITE_THROUGH As Long = &H80000000
Public Const FILE_FLAG_OVERLAPPED As Long = &H40000000

Public Const PIPE_TYPE_MESSAGE As Long = &H4
Public Const PIPE_WAIT As Long = &H0
Public Const PIPE_NOWAIT As Long = &H1
Public Const PIPE_READMODE_MESSAGE As Long = &H2

Public Const PIPE_UNLIMITED_INSTANCES As Long = &HFF




Public Type OVERLAPPED
Internal As Long
InternalHigh As Long
offset As Long
OffsetHigh As Long
hEvent As Long
End Type


Public Type SECURITY_ATTIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type


Public Declare Function CreateThread Lib "Kernel32" ( _
ByRef lpThreadAttributes As Any, _
ByVal Stacksize As Long, _
ByVal lpStartAddress As Long, _
ByRef lpParameter As Any, _
ByVal dwCreationFlags As Long, _
ByRef lpThreadId As Long _
) As Long


Public Declare Function ResumeThread Lib "Kernel32" ( _
ByVal hThreadId As Long _
) As Long

Public Declare Function SuspendThread Lib "Kernel32" ( _
ByVal hThreadId As Long _
) As Long


Public 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, _
ByRef lpSecurityAttributes As Any _
) As Long


Public Declare Function ConnectNamedPipe Lib "Kernel32" ( _
ByVal hNamedPipe As Long, _
ByRef lpOverlapped As Any _
) As Long


Public Declare Function PeekNamedPipe Lib "Kernel32" ( _
ByVal hNamedPipe As Long, _
ByRef lpBuffer As Any, _
ByVal nBuffersize As Long, _
ByRef lpBytesRead As Long, _
ByRef lpTotalBytesAvail As Long, _
ByRef lpBytesleftThisMessage As Long _
) As Long


Public Declare Function CloseHandle Lib "Kernel32" ( _
ByVal hObject As Long _
) As Long


Public Declare Function SetThreadPriority Lib "Kernel32" ( _
ByVal hThread As Long, _
ByVal nPriority As Long _
) As Long


Public Declare Sub ExitThread Lib "Kernel32" ( _
ByVal dwExitCode As Long _
)


Public Declare Function FlushFileBuffers Lib "Kernel32" ( _
ByVal hFile As Long _
) As Long


Public Declare Function DisconnectNamedPipe Lib "Kernel32" ( _
ByVal hNamedPipe As Long _
) As Long



Public Declare Function CreateFile Lib "Kernel32" _
Alias "CreateFileA" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByRef lpSecurityAttributes As SECURITY_ATTIBUTES, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttribute As Long, _
ByVal hTemplateFile As Long _
) As Long



Public Declare Function ReadFile Lib "Kernel32" ( _
ByVal hFile As Long, _
ByRef lpBuffer As Any, _
ByVal nNumberOfBytesToRead As Long, _
ByRef lpNumberOfBytesRead As Long, _
ByRef lpOverlapped As Any _
) As Long


Public Declare Function WriteFile Lib "Kernel32" ( _
ByVal hFile As Long, _
ByRef lpBuffer As Any, _
ByVal nNumberOfBytesToWrite As Long, _
ByRef lpNumberOfBytesWritten As Long, _
ByRef lpOverlapped As Any _
) As Long




Public hPipe As Long
Public hThread As Long
Public lpThreadId As Long
Public bPipeIsConnected As Boolean
Public PipeBuffer As String
Public PipeMsg As String




'Thread will run until client sends 0 for buffersize.
Public Function runConnPipe()
Dim Result As Long
Dim lBytesRead As Long
Dim lBytesWrite As Long
Dim lBytesCount As Long
Dim lNumberOfBytesRead As Long


Do

Result = ConnectNamedPipe(hPipe, ByVal 0)

lNumberOfBytesRead = 4

Result = ReadFile(hPipe, _
lBytesCount, _
LenB(lBytesCount), _
lNumberOfBytesRead, _
ByVal 0)

If lBytesCount <> 0 Then

Form_Formular1.Bezeichnungsfeld4.Caption = lBytesCount & " " & Format(Time, "hh:mm:ss") & vbCrLf & _
PipeBuffer

Result = WriteFile(hPipe, _
PipeBuffer, _
lBytesCount, _
lNumberOfBytesRead, _
ByVal 0)

Result = FlushFileBuffers(hPipe)

End If

Call DisconnectNamedPipe(hPipe)

Loop Until lBytesCount = 0

runConnPipe = 1

End Function

Public Function InitNamedPipe(ByVal PipeName As String)
Dim i As Long




PipeBuffer = String(PIPEBUFFSIZE, Chr(0))


PipeMsg = "Hallo, das ist ein Pipe-Test mit Threads. Wenn das gelesen werden kann, klappt es!"


PipeBuffer = PipeMsg

hPipe = CreateNamedPipe(PipeName, _
PIPE_ACCESS_DUPLEX Or FILE_FLAG_WRITE_THROUGH, _
PIPE_TYPE_MESSAGE Or PIPE_WAIT Or PIPE_READMODE_MESSAGE, _
PIPE_UNLIMITED_INSTANCES, _
PIPEBUFFSIZE, _
PIPEBUFFSIZE, _
10000, _
ByVal 0)

If (hPipe = INVALID_HANDLE_VALUE) Then
MsgBox "Kann pipe nicht erzeugen!", vbExclamation + vbOKOnly, "CreateNamedPipe>Fehler"
Exit Function
End If

hThread = CreateThread(ByVal 0&, _
0&, _
AddressOf runConnPipe, _
ByVal 0&, _
CREATE_SUSPENDED, _
lpThreadId)

If (hThread = 0) Then
MsgBox "konnte Thread nicht erzeugen", vbExclamation + vbOKOnly, "CreateThread>Fehler"
Call CloseHandle(hPipe)
Exit Function
End If

'This does NOT terminate the thread -- the thread continues to run until 'runConnPipe' exits
Call CloseHandle(hThread)

Call SetThreadPriority(lpThreadId, _
THREAD_PRIORITY_NORMAL)

Call ResumeThread(lpThreadId)

End Function


now the form code

Option Compare Database
Option Explicit

Private PipeName As String

Private Sub Befehl0_Click()

Me.txtPipeName.SetFocus
PipeName = Me.txtPipeName.Text

Call InitNamedPipe(PipeName)

End Sub

Private Sub Befehl1_Click()

Call CloseHandle(hPipe)

End Sub




and the client module


Option Compare Database
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, _
ByRef 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

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



and the code for the client's form


Option Compare Database
Option Explicit

Private Const BUFFSIZE As Long = 20000
Private szPipeName As String



Private Sub cmdCallNamedPipe_Click()
Dim res As Long, myStr As String, i As Long, cbRead As Long
Dim numBytes As Long, sMsg As String, temp As String
Dim lBytesRead As Long
Dim lBytesWrite As Long
Dim lBytesleftThisMessage As Long
Dim lBytesCount As Long
Dim lNumberOfBytesRead As Long
Dim OutStr As String
Dim lOutBufferSize As Long



Me.txtReceive.SetFocus
Me.txtReceive.Text = ""
Me.txtUNCPath.SetFocus
szPipeName = Me.txtUNCPath.Text
Me.cmdCallNamedPipe.SetFocus

cbBytes.SetFocus
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

sMsg = String(numBytes, Chr(0))


res = CallNamedPipe(szPipeName, numBytes, LenB(numBytes), _
sMsg, lOutBufferSize, _
cbRead, 30000) 'Wait up to 10 seconds for a response

If res > 0 Then



txtReceive.SetFocus
txtReceive.Text = sMsg 'temp
Else
MsgBox "Error number " & Err.LastDllError & _
" attempting to call CallNamedPipe :" & Err.Description, vbOKOnly
End If
End Sub



I want to use Threads because the application waits for a client to connect
the same to the client, but here i have currently no thread implemention.
The pipe implementation will cause a 234 dll error to the client but won't show any message on the clients textbox. :motz2:




Does anyone know the trick to make the code work or will give a hint how to solve the problems? :help

dancefan
05-28-2012, 05:35 PM
Hi, I am having the same problem with the error number 234 when call CallNamedPipe using VB 6.0. Have you figured out how to fix the problem ? Can I get some experience from you ?

Thanks.


Hi Folks,

first i want to show my problems before i post my code.

1. is it possible to use in MS Access VBA CreateThread(...)
my piece of code will terminate Access after thread termination.

2. I want to create a communication pipe between to processes (MS Access FrontEnd) on different computers.


Here is my code:


First server modul (it creates the pipe)

Option Compare Database
Option Explicit


Public Const PIPEBUFFSIZE As Long = 1024
Public Const PIPETIMEOUT As Long = 50 '50 ms
Public Const INVALID_HANDLE_VALUE As Long = -1

Public Const CREATE_SUSPENDED As Long = &H4
Public Const THREAD_PRIORITY_NORMAL As Long = &H0

Public Const PIPE_ACCESS_DUPLEX As Long = &H3
Public Const PIPE_ACCESS_INBOUND As Long = &H1
Public Const PIPE_ACCESS_OUTBOUND As Long = &H2
Public Const FILE_FLAG_WRITE_THROUGH As Long = &H80000000
Public Const FILE_FLAG_OVERLAPPED As Long = &H40000000

Public Const PIPE_TYPE_MESSAGE As Long = &H4
Public Const PIPE_WAIT As Long = &H0
Public Const PIPE_NOWAIT As Long = &H1
Public Const PIPE_READMODE_MESSAGE As Long = &H2

Public Const PIPE_UNLIMITED_INSTANCES As Long = &HFF




Public Type OVERLAPPED
Internal As Long
InternalHigh As Long
offset As Long
OffsetHigh As Long
hEvent As Long
End Type


Public Type SECURITY_ATTIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type


Public Declare Function CreateThread Lib "Kernel32" ( _
ByRef lpThreadAttributes As Any, _
ByVal Stacksize As Long, _
ByVal lpStartAddress As Long, _
ByRef lpParameter As Any, _
ByVal dwCreationFlags As Long, _
ByRef lpThreadId As Long _
) As Long


Public Declare Function ResumeThread Lib "Kernel32" ( _
ByVal hThreadId As Long _
) As Long

Public Declare Function SuspendThread Lib "Kernel32" ( _
ByVal hThreadId As Long _
) As Long


Public 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, _
ByRef lpSecurityAttributes As Any _
) As Long


Public Declare Function ConnectNamedPipe Lib "Kernel32" ( _
ByVal hNamedPipe As Long, _
ByRef lpOverlapped As Any _
) As Long


Public Declare Function PeekNamedPipe Lib "Kernel32" ( _
ByVal hNamedPipe As Long, _
ByRef lpBuffer As Any, _
ByVal nBuffersize As Long, _
ByRef lpBytesRead As Long, _
ByRef lpTotalBytesAvail As Long, _
ByRef lpBytesleftThisMessage As Long _
) As Long


Public Declare Function CloseHandle Lib "Kernel32" ( _
ByVal hObject As Long _
) As Long


Public Declare Function SetThreadPriority Lib "Kernel32" ( _
ByVal hThread As Long, _
ByVal nPriority As Long _
) As Long


Public Declare Sub ExitThread Lib "Kernel32" ( _
ByVal dwExitCode As Long _
)


Public Declare Function FlushFileBuffers Lib "Kernel32" ( _
ByVal hFile As Long _
) As Long


Public Declare Function DisconnectNamedPipe Lib "Kernel32" ( _
ByVal hNamedPipe As Long _
) As Long



Public Declare Function CreateFile Lib "Kernel32" _
Alias "CreateFileA" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByRef lpSecurityAttributes As SECURITY_ATTIBUTES, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttribute As Long, _
ByVal hTemplateFile As Long _
) As Long



Public Declare Function ReadFile Lib "Kernel32" ( _
ByVal hFile As Long, _
ByRef lpBuffer As Any, _
ByVal nNumberOfBytesToRead As Long, _
ByRef lpNumberOfBytesRead As Long, _
ByRef lpOverlapped As Any _
) As Long


Public Declare Function WriteFile Lib "Kernel32" ( _
ByVal hFile As Long, _
ByRef lpBuffer As Any, _
ByVal nNumberOfBytesToWrite As Long, _
ByRef lpNumberOfBytesWritten As Long, _
ByRef lpOverlapped As Any _
) As Long




Public hPipe As Long
Public hThread As Long
Public lpThreadId As Long
Public bPipeIsConnected As Boolean
Public PipeBuffer As String
Public PipeMsg As String




'Thread will run until client sends 0 for buffersize.
Public Function runConnPipe()
Dim Result As Long
Dim lBytesRead As Long
Dim lBytesWrite As Long
Dim lBytesCount As Long
Dim lNumberOfBytesRead As Long


Do

Result = ConnectNamedPipe(hPipe, ByVal 0)

lNumberOfBytesRead = 4

Result = ReadFile(hPipe, _
lBytesCount, _
LenB(lBytesCount), _
lNumberOfBytesRead, _
ByVal 0)

If lBytesCount <> 0 Then

Form_Formular1.Bezeichnungsfeld4.Caption = lBytesCount & " " & Format(Time, "hh:mm:ss") & vbCrLf & _
PipeBuffer

Result = WriteFile(hPipe, _
PipeBuffer, _
lBytesCount, _
lNumberOfBytesRead, _
ByVal 0)

Result = FlushFileBuffers(hPipe)

End If

Call DisconnectNamedPipe(hPipe)

Loop Until lBytesCount = 0

runConnPipe = 1

End Function

Public Function InitNamedPipe(ByVal PipeName As String)
Dim i As Long




PipeBuffer = String(PIPEBUFFSIZE, Chr(0))


PipeMsg = "Hallo, das ist ein Pipe-Test mit Threads. Wenn das gelesen werden kann, klappt es!"


PipeBuffer = PipeMsg

hPipe = CreateNamedPipe(PipeName, _
PIPE_ACCESS_DUPLEX Or FILE_FLAG_WRITE_THROUGH, _
PIPE_TYPE_MESSAGE Or PIPE_WAIT Or PIPE_READMODE_MESSAGE, _
PIPE_UNLIMITED_INSTANCES, _
PIPEBUFFSIZE, _
PIPEBUFFSIZE, _
10000, _
ByVal 0)

If (hPipe = INVALID_HANDLE_VALUE) Then
MsgBox "Kann pipe nicht erzeugen!", vbExclamation + vbOKOnly, "CreateNamedPipe>Fehler"
Exit Function
End If

hThread = CreateThread(ByVal 0&, _
0&, _
AddressOf runConnPipe, _
ByVal 0&, _
CREATE_SUSPENDED, _
lpThreadId)

If (hThread = 0) Then
MsgBox "konnte Thread nicht erzeugen", vbExclamation + vbOKOnly, "CreateThread>Fehler"
Call CloseHandle(hPipe)
Exit Function
End If

'This does NOT terminate the thread -- the thread continues to run until 'runConnPipe' exits
Call CloseHandle(hThread)

Call SetThreadPriority(lpThreadId, _
THREAD_PRIORITY_NORMAL)

Call ResumeThread(lpThreadId)

End Function


now the form code

Option Compare Database
Option Explicit

Private PipeName As String

Private Sub Befehl0_Click()

Me.txtPipeName.SetFocus
PipeName = Me.txtPipeName.Text

Call InitNamedPipe(PipeName)

End Sub

Private Sub Befehl1_Click()

Call CloseHandle(hPipe)

End Sub




and the client module


Option Compare Database
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, _
ByRef 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

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



and the code for the client's form


Option Compare Database
Option Explicit

Private Const BUFFSIZE As Long = 20000
Private szPipeName As String



Private Sub cmdCallNamedPipe_Click()
Dim res As Long, myStr As String, i As Long, cbRead As Long
Dim numBytes As Long, sMsg As String, temp As String
Dim lBytesRead As Long
Dim lBytesWrite As Long
Dim lBytesleftThisMessage As Long
Dim lBytesCount As Long
Dim lNumberOfBytesRead As Long
Dim OutStr As String
Dim lOutBufferSize As Long



Me.txtReceive.SetFocus
Me.txtReceive.Text = ""
Me.txtUNCPath.SetFocus
szPipeName = Me.txtUNCPath.Text
Me.cmdCallNamedPipe.SetFocus

cbBytes.SetFocus
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

sMsg = String(numBytes, Chr(0))


res = CallNamedPipe(szPipeName, numBytes, LenB(numBytes), _
sMsg, lOutBufferSize, _
cbRead, 30000) 'Wait up to 10 seconds for a response

If res > 0 Then



txtReceive.SetFocus
txtReceive.Text = sMsg 'temp
Else
MsgBox "Error number " & Err.LastDllError & _
" attempting to call CallNamedPipe :" & Err.Description, vbOKOnly
End If
End Sub



I want to use Threads because the application waits for a client to connect
the same to the client, but here i have currently no thread implemention.
The pipe implementation will cause a 234 dll error to the client but won't show any message on the clients textbox. :motz2:




Does anyone know the trick to make the code work or will give a hint how to solve the problems? :help