Registriert seit: 18. Apr 2004
47 Beiträge
Delphi 7 Enterprise
|
Re: Zwei Prozesse mittels NamedPipe/ Pipe kommunizieren lass
4. Sep 2004, 17:21
Also ich hab mir mal das alles durchgelsen. Allerdings funzt das iregendwie nicht.
Programm A:
Delphi-Quellcode:
var
Form1: TForm1;
Pipe : THandle;
implementation
{$R *.dfm}
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:= CreateNamedPipe('test', PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE or
PIPE_READMODE_MESSAGE or PIPE_WAIT or SECURITY_ANONYMOUS,
PIPE_UNLIMITED_INSTANCES, 1024,
1024, NMPWAIT_USE_DEFAULT_WAIT, @FSA);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
buffer: string;
dw : dword;
begin
buffer:= 'test';
WriteFile(Pipe, buffer, sizeof(buffer), dw, nil);
end;
Programm B:
Delphi-Quellcode:
var
Form1: TForm1;
pipe : THandle;
implementation
{$R *.dfm}
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 := CreateNamedPipe(
PChar('test'), PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE or
PIPE_READMODE_MESSAGE or PIPE_WAIT or SECURITY_ANONYMOUS,
PIPE_UNLIMITED_INSTANCES, 1024,
1024, NMPWAIT_USE_DEFAULT_WAIT, @FSA);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
buffer: string;
dw : dword;
begin
ReadFile(pipe, Buffer, 100, dw, nil);
Label1.Caption:= buffer;
end;
|
|
Zitat
|