DWORD WINAPI ThreadProc(void* p)
/*线程控制函数*/
{
MSG msg;
while (::GetMessage(&msg, NULL, 0, 0))
{
switch(msg.message)
{
case MYMESSAGE:
dosomething();
/*在这里完成主程序传来的任务*/
busy[*(int*)p]=false;
/*工作完成,设置为不忙*/
break;
default:
break;
}
}
return 0;
}这么改怎么样?
/*线程控制函数*/
{
MSG msg;
while (::GetMessage(&msg, NULL, 0, 0))
{
switch(msg.message)
{
case MYMESSAGE:
dosomething();
/*在这里完成主程序传来的任务*/
busy[*(int*)p]=false;
/*工作完成,设置为不忙*/
break;
default:
break;
}
}
return 0;
}这么改怎么样?
[*(int*)p] : 将void类型的指针p转换为int类型的指针,然后取出该指针地址中的值(是值不是地址)就这样
{
switch(msg.message)
{
...
case WM_QUIT:
return 5;
... }
}有可能被执行到吗?
BOOL GetExitCodeThread(
HANDLE hThread, // handle to the thread
LPDWORD lpExitCode // address to receive termination status
);
获得线程的退出值,如果你想知道线程为什么退出从哪里退出的话
如果线程依然运行, GetExitCodeThread得到的是STILL_ACTIVE
#define STATUS_PENDING ((DWORD )0x00000103L)
所以最好不用这个值做thread的return值。