#include "Windows.h"
#include <stdlib.h>
#include <stdio.h>
DWORD WINAPI ThreadFunc(LPVOID param)
{
printf("启动线程\n");
return 0;
}
int main()
{
DWORD threadID = 0;
HANDLE threadObj = NULL;
threadObj = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc, NULL, 0, &threadID);
if (threadObj == NULL) {
printf("创建线程失败。");
return 1;
}
Sleep(1000);
CloseHandle(threadObj);
printf("主线程结束。\n");
return 0;
}
输出:
启动线程
主线程结束。
参考: 《Visual C++ 编程实战宝典》 P587 标签:return,WINAPI,threadObj,线程,测试,printf,NULL From: https://www.cnblogs.com/huvjie/p/18007774