S
SuperLunatic
Unregistered / Unconfirmed
GUEST, unregistred user!
用Delphi写了一个多线程的 Chile.exe :是画3个不同的图。
又写一个 Parent.exe:利用管道调用 Chile.exe !
我现在在Parent里建立了管道,子进程。请问我怎么从管道发消息,让子进程响应。
var
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
SecurityAttributes: TSecurityAttributes;
ChildInput,MyOutput: THANDLE;
s:string;
Bytes: Cardinal;
Application.ProcessMessages;
SecurityAttributes.nLength := sizeof(SECURITY_ATTRIBUTES);
SecurityAttributes.lpSecurityDescriptor := nil;
SecurityAttributes.bInheritHandle := True;
// 建立管道
if not CreatePipe(ChildInput, MyOutput, @SecurityAttributes, 0) then
RaiseLastWin32Error;
FillChar(StartupInfo,SizeOf(StartupInfo),0);
with StartupInfo do
begin
cb := SizeOf(StartupInfo);
dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
wShowWindow := SW_Normal;
hStdInput := GetStdHandle(STD_INPUT_HANDLE);
hStdOutput := MyOutput;
hStdError := MyOutput;
end;
//创建子进程
If CreateProcess(nil,'child.exe',nil,nil,
True,0,nil,nil,StartupInfo,ProcessInfo) Then
Begin
CloseHandle(MyOutput);
repeat
ReadFile(ChildInput, s, 1, Bytes, nil);
until Bytes = 0;
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
End
Else ShowMessage('创建失败: '+
SysErrorMessage(GetLastError));
又写一个 Parent.exe:利用管道调用 Chile.exe !
我现在在Parent里建立了管道,子进程。请问我怎么从管道发消息,让子进程响应。
var
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
SecurityAttributes: TSecurityAttributes;
ChildInput,MyOutput: THANDLE;
s:string;
Bytes: Cardinal;
Application.ProcessMessages;
SecurityAttributes.nLength := sizeof(SECURITY_ATTRIBUTES);
SecurityAttributes.lpSecurityDescriptor := nil;
SecurityAttributes.bInheritHandle := True;
// 建立管道
if not CreatePipe(ChildInput, MyOutput, @SecurityAttributes, 0) then
RaiseLastWin32Error;
FillChar(StartupInfo,SizeOf(StartupInfo),0);
with StartupInfo do
begin
cb := SizeOf(StartupInfo);
dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
wShowWindow := SW_Normal;
hStdInput := GetStdHandle(STD_INPUT_HANDLE);
hStdOutput := MyOutput;
hStdError := MyOutput;
end;
//创建子进程
If CreateProcess(nil,'child.exe',nil,nil,
True,0,nil,nil,StartupInfo,ProcessInfo) Then
Begin
CloseHandle(MyOutput);
repeat
ReadFile(ChildInput, s, 1, Bytes, nil);
until Bytes = 0;
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
End
Else ShowMessage('创建失败: '+
SysErrorMessage(GetLastError));