_beginthread()函数是创建线程的一个简洁函数,参数比较少;
// win32thrddemo.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <Windows.h>
#include <process.h>
#include <iostream>
using namespace std;
//DWORD WINAPI ThreadFuncFirst(LPVOID param)
void ThreadFuncFirst(void* param)
{
int iCount = 50;
while (iCount--) {
cout << "\nThreadFuncFirst:" << iCount;
}
//_endthread();
//cout << "线程结束" << endl;
}
int main()
{
HANDLE handleFirst = (HANDLE)_beginthread(ThreadFuncFirst, 0, NULL);
WaitForSingleObject(handleFirst, INFINITE);
CloseHandle(handleFirst);
return 0;
}
_beginthread()的头文件是process.h;
要使用HANDLE、CloseHandle则必须包含Windows.h;<