线程参数?????(50分)

  • 主题发起人 主题发起人 MaxWoods
  • 开始时间 开始时间
M

MaxWoods

Unregistered / Unconfirmed
GUEST, unregistred user!
program Thread3;
{$APPTYPE CONSOLE}
uses SysUtils,Windows;
var hThrd1,hThrd2:Cardinal;exitCode1,exitCode2,threadID:LongWord;
i:Cardinal;
function ThreadFunc(p:Pointer):LongWord;
begin
Sleep(Cardinal(p)*1000*2);
Write(Cardinal(p));
Write(#$D#$A);
Result:=Cardinal(p)*10;
end;

begin

exitCode1:=0;
exitCode2:=0;

i:=Cardinal(1);
hThrd1:=CreateThread(nil,0,@ThreadFunc,@i,0,threadID);
if(hThrd1<>0) then
Write('Thread 1 launched'#$D#$A);
i:=Cardinal(2);
hThrd2:=CreateThread(nil,0,@ThreadFunc,@i,0,threadID);
if(hThrd2<>0) then
Write('Thread 2 launched'#$D#$A);
repeat
//这里要等待键盘输入,怎么写?
GetExitCodeThread(hThrd1,exitCode1);
GetExitCodeThread(hThrd2,exitCode2);
until ((exitCode1<>STILL_ACTIVE) and (exitCode2<>STILL_ACTIVE));
CloseHandle(hThrd1);
CloseHandle(hThrd2);
Write('Thread 1 returned ',exitCode1,#$D#$A);
Write('Thread 2 returned ',exitCode2,#$D#$A);
ExitCode:=0;

end.

还有,上面程序运行后,Thread1,Thread2总里返回0,但线程参数不是0,为什么?
 
function ThreadFunc(p:Pointer):LongWord;stdcall;
~~~~~~~
 

Similar threads

I
回复
0
查看
518
import
I
I
回复
0
查看
654
import
I
I
回复
0
查看
499
import
I
I
回复
0
查看
843
import
I
后退
顶部