如果一个主进程可以创建多个子进程。如何实现主进程与子进程之间的通讯,而且主进程完成与子进程通讯完后,主进程可以关闭子进程。
愿听高论!
愿听高论!
解决方案 »
- 关于将两个变量保存到一起
- 与朋友合作做软件,应如何分享收入??
- 老问题了,但我还不是很清楚,关于连接oracle到底用啥控件比较好???
- 如何对多表连接查出的DBGRID的记录复选删除?
- MIDAS问题关于DCOM的问题
- 请教一个BDE和SQL SERVER 7.0连接问题
- delphi函数
- 关于StringGrid控件的高级使用,高手请进!!!!!!!!!!!!!!!!!
- Button.Enabled=False时颜色变灰,Groupbox.Enabled=False颜色怎么不变?如何才能让它自动变灰?
- 关于窗口的事件响应问题,高分送出!!!!!!!
- 有没有F1BOOK FOR DELPHI 6 ,我身边的只能在DILPHI5上用,6就不行了
- 调用这个函数怎么提示:参数错误?——关于函数参数传递问题
至于关闭某一个进程
terminateThread
直接杀死它..
小数据可用消息,自定义一个消息,以广播的方式发送就可以了,
如果使用共享内存,可能还需要使用TEvent来进行同步。一小段程序:
======
呼叫方:
function CreateMapFile(var AMappingHandle:THandle;var AMemory:Pointer;ADesiredSize:DWORD):Boolean;
begin
Result:=false;
AMappingHandle:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,ADesiredSize,ProgramGUID);
if AMappingHandle=0 then
exit;
AMemory:=MapViewOfFile(AMappingHandle,FILE_MAP_WRITE,0,0,0);
if AMemory=nil then
exit;
Result:=true;
end;function ReleaseMapFile(var AMappingHandle:THandle;var AMemory:Pointer):Boolean;
begin
Result:=false;
if AMemory<>nil then begin
if not UnmapViewOfFile(AMemory) then
exit;
AMemory:=nil;
end;
if AMappingHandle<>0 then begin
if not CloseHandle(AMappingHandle) then
exit;
AMappingHandle:=0;
end;
Result:=true;
end;procedure ShowPhotoEnhanceForm(AOwner:TComponent;AFileName:String);
var
MemStream:TMemoryStream;
MappingHandle:THandle;
Memory:Pointer;
Event:TEvent;
begin
MemStream:=TMemoryStream.Create();
try
if not GetImageStream(AFileName,MemStream) then begin
raise Exception.Create('ShowPhtotEnhanceForm: error when get image stream!');
end;
if not CreateMapFile(MappingHandle,Memory,MemStream.Size) then begin
raise Exception.Create('ShowPhotoEnhanceForm: error when create map file!');
end;
try
Event:=TEvent.Create(nil,true,false,EventGUID);
Event.ResetEvent();
try
MemStream.Position:=0;
MemStream.ReadBuffer(Memory^,MemStream.Size);
if ShellExecute(Application.Handle,'open',pChar(GetPEPathName()),pChar('/m'+IntToStr(MemStream.Size)),'',SW_NORMAL)<=32 then begin
raise Exception.Create('ShowPhotoEnhanceForm: error to execute photo enhance!');
end;
case Event.WaitFor(WaitTimeout) of
//wrSignaled:
wrTimeout: raise Exception.Create('ShowPhotoEnhanceForm: The time specified by the TimeOut parameter elapsed without the signal being set.');
wrAbandoned:raise Exception.Create('ShowPhotoEnhanceForm: The event object was destroyed before the TimeOut period elapsed.');
wrError: raise Exception.Create('ShowPhotoEnhanceForm: An error occurred while waiting.');
end;
finally
Event.Free;
end;
finally
if not ReleaseMapFile(MappingHandle,Memory) then begin
raise Exception.Create('ShowPhotoEnhanceForm: error when release map file!');
end;
end;
finally
MemStream.Free;
end;
end;
接收方:
procedure TMainForm.GetMemoryBitmap(AMemSize:DWORD;var ABitmap:TBitmap);
const
ProgramGUID='{E95E2974-C6A3-45BA-AC0A-876FCF9523FD}';
EventGUID='{56717769-5DD0-4B20-830A-43A6AB753E1F}';
var
MappingHandle:THandle;
Memory:Pointer;
MemStream:TMemoryStream;
Event:TEvent;
begin
try
MemStream:=TMemoryStream.Create();
try
MappingHandle:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,AMemSize,ProgramGUID);
if MappingHandle=0 then
raise Exception.Create('GetMemoryBitmap: error when create mapping file!');
Memory:=MapViewOfFile(MappingHandle,FILE_MAP_WRITE,0,0,0);
if Memory=nil then
raise Exception.Create('GetMemoryBitmap: error when map view of file!');
MemStream.Size:=AMemSize;
MemStream.Position:=0;
MemStream.WriteBuffer(Memory^,AMemSize);
MemStream.Position:=0;
ABitmap.LoadFromStream(MemStream);
finally
if Memory<>nil then
UnmapViewOfFile(Memory);
if MappingHandle<>0 then
CloseHandle(MappingHandle);
MemStream.Free;
end;
finally
Event:=TEvent.Create(nil,true,false,EventGUID);
try
Event.SetEvent();
finally
Event.Free;
end;
end;
end;
1、全局变量通讯,
2、进程间发送消息;
发送消息的话比较复杂,一般用全局变量比较简单些,但是注意不要引起冲突!
另外我觉得你最好去
http://net-edu.hdpu.edu.cn/teach/network/DELPHI%205%E5%BC%80%E5%8F%91%E4%BA%BA%E5%91%98%E6%8C%87%E5%8D%97/
将《程序员开发指南》一书下载下来,比较好,讲的进程很详细~~~~
强烈推荐!!!!!!!!!!!!!!
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/using_event_objects.asp