Hello!
I want to use Named Pipes to communicate between two programs.
With the Windows function I manage to create a named pipe, but unfortunately I fail to write into the pipe.
What am I doing wrong?
uses Windows;
function Server_createPipe(): THandle;
var
SD: SECURITY_DESCRIPTOR;
SA: SECURITY_ATTRIBUTES;
const
PIPE_UNLIMITED_INSTANCES = 255;
begin
InitializeSecurityDescriptor(@SD, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(@SD, true, nil{ACL}, false);
SA.lpSecurityDescriptor := @SD;
SA.nLength := SizeOf(SA);
SA.bInheritHandle := true;
Result := CreateNamedPipe(PChar('\\.\pipe\Test'),
PIPE_ACCESS_DUPLEX or FILE_FLAG_WRITE_THROUGH,
PIPE_TYPE_BYTE or PIPE_NOWAIT, // others: PIPE_TYPE_MESSAGE or PIPE_READMODE_MESSAGE
PIPE_UNLIMITED_INSTANCES,
1024,
1024,
50,
@SA);
end;
function writeToPipe(Pipe: THandle; const s: String): Boolean;
var written: DWord;
begin
if s='' then Exit(true);
Result := WriteFile(Pipe, s[1], Length(s), {out}written, nil);
end;
The handle seems to be correct (value 252), but WriteFile always returns false.