请问一下,我们用BeginThread创始一个线程后,我们理解为打开了一个函数,我们能不能读取这个函数的返回值,我们一般用GetLastError获得的错误值,跟这个函数的返回值没关系吧

解决方案 »

  1.   

    "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);
      

  2.   

     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);
      

  3.   

    [Error] AnyViewConsole.pas(170): Types of actual and formal var parameters must be identical
    调用这个CreateThread还有这个错误
      

  4.   

    这是VC吗?看起来像Dephi啊,
      

  5.   

    就是delphi
    readDataFromMapFile()是在mfc下写的dll
      

  6.   

    hThread:=CreateThread(nil,0,@readDataFromMapFile(@showRealLog),nil,0,nil); @readDataFromMapFile(@showRealLog)是什么东西?改成 
    hThread:=CreateThread(nil,0,@readDataFromMapFile, @showRealLog,0,nil); 试试
      

  7.   

    线程函数只能是
    function(Parameter: Pointer): Integer;
    GetExitCodeThread拿到的就是那个返回值
    如果要传递更多的东西,吧返回值当成Pointer,指向一个你自己定义的类或者记录体就行了
      

  8.   

    我利用GetExitCodeThread(hThread,word);
    word拿到的一直是259,word是DWord类型,为什么会这样
      

  9.   

    GetExitCodeThread(hThread,word); 
    最好不要用这个来查询线程函数的返回值,因为线程还在运行时会返回still_run(259),exitCode的值也就不是你要值到的值了