请问HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes,
                 DWORD dwStackSize,
                 LPTHREAD_START_ROUTINE lpStartAddress,
                 LPVOID lpParameter,
                 DWORD dwCreationFlags,
                 LPDWORD lpThreadId);
申请的线程我怎么等到里面函数的返回值?

// TODO: Add your control notification handler code here
hThread=CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)ThreadFunc,
NULL,
0,
&ThreadID);
ThreadFunc是整型返回值我怎么得到,怎么写,在线等,谢谢!

解决方案 »

  1.   

    等待线程结束,调用GetExitCodeThread
      

  2.   

    见MSDN:A process can obtain the return value of the ThreadProc of a thread it created with CreateThread by calling the GetExitCodeThread function. A process cannot obtain the return value from the ThreadProc of a thread it created with CreateRemoteThread. 所以楼上说得对。
      

  3.   

    线程不能停,循环的,我要实时的得到ThreadFunc返回值
      

  4.   

    补充楼上的,首先调用WaitForSingleObject等待线程结束,然后调用GetExitCodeThread获取返回值。
      

  5.   

    ThreadFunc 返回的时候 也就是线程结束的时候~~ 明白?
      

  6.   


    ThreadFunc返回了,线程就结束了。如果要在中途获取一些值,可以使用消息等其他方法。
      

  7.   

    在线程中dwEvent = WaitForSingle()等待一个事件,当想得到变量值的时候,触发事件,
    switch(dw) 
    case dwEvent :
    sendmessage();
    break ;
      

  8.   

    记得《windows核心编程》里在讲线程时,就是这样说的,线程函数返回,也就意味着这个线程结束了
      

  9.   

    线程不结束就没有返回值,你要做的是得到线程的中间运行状态,有很多种方法,例如从线程中 PostMessage 或 SendMessage / PostThreadMessage 给关心基状态的线程
    也可以用全局变量(或者从线程参数中传递进来的变量)+同步机制