我在一个进程A中调用另一个进程B,我想等B执行完后再执行A,怎么做? (100分)

  • 主题发起人 主题发起人 lovesun
  • 开始时间 开始时间
L

lovesun

Unregistered / Unconfirmed
GUEST, unregistred user!
??????????????????
 
我有办法,不过代码在单位了,你来封EMIAL,明天给你发过去,保证好用。
b5790930@pub.xz.jsinfo.net
 
up:
我的email是wgang@sinobnet.com
谢谢。
 
To: truecat:
能否发一份给我,我也想学一下!谢谢
 

CreateProcess
使用WaitForSingleObject(。。。),具体你查看MSDN

 
学习!!LoveFlower521@sohu.com
 
to truecat:如果不介意的话,当你有空的话,mei给我一个。我也想学习学习,谢谢先。
Email:zwz_good@sohu.com
 
procedure TForm1.Button1Click(Sender: TObject);
var
sCommandLine: string;
bCreateProcess: boolean;
lpStartupInfo: TStartupInfo;
lpProcessInformation: TProcessInformation;
begin
sCommandLine := 'Arj /?';
bCreateProcess := CreateProcessA(nil, PChar(sCommandLine),
nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil,
lpStartupInfo, lpProcessInformation);
if bCreateProcess then
WaitForSingleObject(lpProcessInformation.hProcess, INFINITE);
end;
 
WaitForSingleObject很容易使消息阻塞的,还是在线程中用比较好!
 
To: truecat:
能否发一份给我,我也想学一下!谢谢
yan_77@sohu.com
 
to:truecat:
我也想学一下 shwonl@sohu.com
谢谢!
 
贴上源码,大家自己看吧,源码出自DFW的老贴子上面:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, WinProcs, ShellAPI;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
cmdStr:pchar;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
cmdstr:=pchar('RunDLL32.exe Shell32.DLL,Control_RunDLL Intl.cpl,,4');
{建立进程并等待其结束}
fillchar(StartupInfo,sizeof(StartupInfo),0);
CreateProcess(nil,cmdstr,nil,nil,false,0,nil,nil,StartupInfo,ProcessInfo);
With ProcessInfo do
begin
CloseHandle(hThread);
WaitForSingleObject(hProcess, INFINITE);
CloseHandle(hProcess);
end;
end;
end.
 
后退
顶部