I am attempting to use rllibby's "Pipes" component in a console application. Everything works great when I create a VCL "client" app and a VCL "server" app. The 2 apps are quite simple, and simply send messages back and forth from exe to exe.
I attempted to rewrite the VCL client app as a console application and am now stuck. The code appears to me to be essentially the same, and when I step through with the debugger I see that the client is connecting and it is supposedly writing to the pipe (true is returned). However, nothing ever shows up in my server VCL app. But, if I launch the client VCL version and send a message, everything is great. Here is the code I am using in my console application. The pipe is named "myNamedPipe", and the VCL server app is launched first and actually activates the pipe before I run the client:
//////////////////////////
//////////
//////////
//////////
//////////
//////////
/////////
//start of code
program CmdClient;
{$APPTYPE CONSOLE}
uses
SysUtils,
Pipes;
var
wideChars : array[0..255] of WideChar;
myString : String;
bSuccess01, bSuccess02 : Boolean;
iLength : integer;
PipeClient1 : TPipeClient;
begin
PipeClient1 := TPipeClient.Create(nil);
try
begin
with PipeClient1 do
begin
Name := 'myNamedPipe';
PipeName := 'myNamedPipe';
ServerName := '.';
//OnPipeMessage := PipeClient1PipeMessage;
end;
myString := 'the message I am sending';
iLength := Length(myString)+1;
StringToWideChar(myString,
wideChars,
iLength);
bSuccess01 := PipeClient1.Connect(5000);
WriteLn('Success: ' + BoolToStr(bSuccess01));
bSuccess02 := PipeClient1.Write(wideChar
s,iLength*
2);
WriteLn('s2: ' + BoolToStr(bSuccess02));
end;
finally
FreeAndNil(PipeClient1);
end;
end.
// end of code
//////////////////////////
//////////
//////////
//////////
//////////
//////////
////////
This is a bit outside the scope of the original question, but I'll ask anyway. I'd also like to be able to use the OnPipeMessage event in my console application, but I haven't found a way to do it from a console app. Is it possible to use this event from a console application?
Regards
Start Free Trial