I managed to load the engine and receive the first couple of lines from the engine. Then I tried to send the "uci" command from the GUI to the Engine but I am not getting any response. Because receiving is working at the beginning I assume that the problem lies within the send code.
I took the main structure from winboard.c and translated it to Visual Basic code. Am I missing anything?
Code: Select all
Public Sub EngineRun()
Dim start As STARTUPINFO
Dim sa As SECURITY_ATTRIBUTES
Dim L As Long, Result As Long, bSuccess As Long
Dim Buffer As String
sa.nLength = Len(sa)
sa.bInheritHandle = 1&
sa.lpSecurityDescriptor = 0&
Result = CreatePipe(hChildStdoutRd, hChildStdoutWr, sa, 1024 * 16)
Result = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd, _
GetCurrentProcess(), hChildStdoutRdDup, 0, _
False, DUPLICATE_SAME_ACCESS)
If Result = 0 Then
MsgBox "CreatePipe failed Error!"
Exit Sub
End If
CloseHandle hChildStdoutRd
Result = CreatePipe(hChildStdinRd, hChildStdinWr, sa, 0)
Result = DuplicateHandle(GetCurrentProcess(), hChildStdinWr, _
GetCurrentProcess(), hChildStdinWrDup, 0, _
False, DUPLICATE_SAME_ACCESS)
If Result = 0 Then
MsgBox "CreatePipe failed Error!"
Exit Sub
End If
CloseHandle hChildStdinWr
start.cb = Len(start)
start.dwFlags = STARTF_USESTDHANDLES
start.hStdInput = hChildStdinRd
start.hStdOutput = hChildStdoutWr
start.hStdError = hChildStdoutWr
Result = CreateProcessA(0&, EnginePath, 0&, 0&, 1&, &H8000000, 0&, 0&, start, proc)
ProcID = proc.hProcess
If Result <> 0 Then
Dim lPeekData As Long
Do
Call PeekNamedPipe(hChildStdoutRdDup, ByVal 0&, 0&, ByVal 0&, lPeekData, ByVal 0&)
If lPeekData > 0 Then
Buffer = Space$(lPeekData)
bSuccess = readFile(hChildStdoutRdDup, Buffer, Len(Buffer), L, 0&)
If bSuccess = 1 Then
[...]
Else
MsgBox "ReadFile failed!"
End If
Else
bSuccess = WaitForSingleObject(proc.hProcess, 0&)
If bSuccess = 0 Then Exit Do
End If
DoEvents
Loop
Else
MsgBox "Error while starting process!"
End If
TerminateProcess proc.hProcess, 0
Call CloseHandle(proc.hProcess)
Call CloseHandle(proc.hThread)
Call CloseHandle(hReadPipe)
Call CloseHandle(hWritePipe)
End Sub
Public Sub EngineSend()
Dim b(256)
Dim data As String
data = "uci" & vbCrLf
Call CopyMemory(b(0), data, Len(data))
fSuccess = WriteFile(hChildStdinWrDup, b(0), Len(data), lBytesWritten, 0)
'FlushFileBuffers hChildStdinWrDup
End Sub