我的代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
DWORD WINAPI ThreadFunc(LPVOID);
void AnotherFunc(void);
int main()
{
HANDLE hThrd;
int flag=0;
DWORD exitCode=0;
DWORD threadId=0;
hThrd=CreateThread(NULL,0,ThreadFunc,(LPVOID)1,0,&threadId);
flag++;
//Sleep(2000);
if(hThrd)
{
printf("launched \n");
printf("%d\n",flag);
}
for(;;)
{
BOOL rc;
rc=::GetExitCodeThread(hThrd,&exitCode);
if(rc && exitCode!=STILL_ACTIVE)
break;
}
::CloseHandle(hThrd);
printf("returned %d\n",exitCode);
return EXIT_SUCCESS;
}
DWORD WINAPI ThreadFunc(LPVOID n)
{
printf("running \n");
AnotherFunc();
return 0;
}
void AnotherFunc()
{
::ExitThread(4);
}
输出结果为:
launched
launched
running
1
returned 4
请高手帮忙 现在小弟没分 以后会弥补的!!!