Einzelnen Beitrag anzeigen

Scorpion3000

Registriert seit: 18. Apr 2004
47 Beiträge
 
Delphi 7 Enterprise
 
#9

Re: Zwei Prozesse mittels NamedPipe/ Pipe kommunizieren lass

  Alt 31. Jan 2005, 13:16
Kleiner Nachtrag: so funktioniert die ganze Sache:

Programm A:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var
   FSA : SECURITY_ATTRIBUTES;
   FSD : SECURITY_DESCRIPTOR;
   pch1: shortstring;
begin
   InitializeSecurityDescriptor(@FSD, SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(@FSD, True, nil, False);
   FSA.lpSecurityDescriptor := @FSD;
   FSA.nLength := sizeof(SECURITY_ATTRIBUTES);
   FSA.bInheritHandle := True;

   Pipe:= CreateNamedPipe(PChar('\\.\pipe\<test>'),
                          PIPE_ACCESS_DUPLEX or FILE_FLAG_WRITE_THROUGH,
                          PIPE_TYPE_MESSAGE or PIPE_READMODE_MESSAGE or PIPE_NOWAIT,
                          PIPE_UNLIMITED_INSTANCES,
                          1024,
                          1024,
                          50,
                          @FSA);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   buffer: shortstring;
   dw : dword;
   b1 : boolean;
begin
   buffer:= 'Test';
   WriteFile(Pipe, buffer, sizeof(buffer), dw, nil);
end;
Programm B:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var
   FSA : SECURITY_ATTRIBUTES;
   FSD : SECURITY_DESCRIPTOR;
begin
   InitializeSecurityDescriptor(@FSD, SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(@FSD, True, nil, False);
   FSA.lpSecurityDescriptor := @FSD;
   FSA.nLength := sizeof(SECURITY_ATTRIBUTES);
   FSA.bInheritHandle := True;

   Pipe:= CreateFile(PChar('\\.\pipe\<test>'),
                     GENERIC_READ or GENERIC_WRITE,
                     0,
                     @FSA,
                     OPEN_EXISTING,
                     0,
                     0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   buffer: shortstring;
   dw : dword;
begin
   ReadFile(Pipe, buffer, sizeof(buffer), dw, nil);
end;

Mfg Scorpion3000
  Mit Zitat antworten Zitat