"GetLastError获得的错误值,跟这个函数的返回值没关系" (correct)读取这个函数的返回值: HANDLE hThread = CreateThread(...);// if the thread is still running, retVal == STILL_ACTIVE DWORD retVal; GetExitCodeThread(hThread, &retVal);...// wait for the thread to exit and now you get the exit value WaitForSingleObject(hThread, INFINITE); GetExitCodeThread(hThread, &retVal);
hThread:=CreateThread(nil,0,@readDataFromMapFile(@showRealLog),nil,0,nil); 我这个函数怎么会提示 variable requried 附: private { Private declarations } public { Public declarations } end; callBackFunction= procedure(pl: pchar;pr: pchar); procedure showRealLog(v_pcWndName,v_pcIP:Pchar);stdcall; var Form1: TForm1; function readDataFromMapFile(v_pf:callBackFunction):Integer;stdcall; implementation function readDataFromMapFile(v_pf:callBackFunction):Integer;stdcall;external'readDataDll' {$R *.dfm} ...... hThread:=CreateThread(nil,0,@readDataFromMapFile(@showRealLog),nil,0,nil);
[Error] AnyViewConsole.pas(170): Types of actual and formal var parameters must be identical 调用这个CreateThread还有这个错误
HANDLE hThread = CreateThread(...);// if the thread is still running, retVal == STILL_ACTIVE
DWORD retVal;
GetExitCodeThread(hThread, &retVal);...// wait for the thread to exit and now you get the exit value
WaitForSingleObject(hThread, INFINITE);
GetExitCodeThread(hThread, &retVal);
我这个函数怎么会提示 variable requried
附:
private
{ Private declarations }
public
{ Public declarations }
end;
callBackFunction= procedure(pl: pchar;pr: pchar);
procedure showRealLog(v_pcWndName,v_pcIP:Pchar);stdcall;
var
Form1: TForm1;
function readDataFromMapFile(v_pf:callBackFunction):Integer;stdcall;
implementation
function readDataFromMapFile(v_pf:callBackFunction):Integer;stdcall;external'readDataDll'
{$R *.dfm}
......
hThread:=CreateThread(nil,0,@readDataFromMapFile(@showRealLog),nil,0,nil);
调用这个CreateThread还有这个错误
readDataFromMapFile()是在mfc下写的dll
hThread:=CreateThread(nil,0,@readDataFromMapFile, @showRealLog,0,nil); 试试
function(Parameter: Pointer): Integer;
GetExitCodeThread拿到的就是那个返回值
如果要传递更多的东西,吧返回值当成Pointer,指向一个你自己定义的类或者记录体就行了
word拿到的一直是259,word是DWord类型,为什么会这样
最好不要用这个来查询线程函数的返回值,因为线程还在运行时会返回still_run(259),exitCode的值也就不是你要值到的值了