//了解即可,因为有更好的替代,vs下转到定义即可查看(不会,没关系,看我就够了)
CreateThread(
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ SIZE_T dwStackSize,
_In_ LPTHREAD_START_ROUTINE lpStartAddress,
_In_opt_ __drv_aliasesMem LPVOID lpParameter,
_In_ DWORD dwCreationFlags,
_Out_opt_ LPDWORD lpThreadId
);
参数说明:参照<<windows核心编程>>,或者百度也行,真的不想写啊,要不我们看例子嘛
#include <iostream>
#include <string>
#include <process.h>
#include <Windows.h>
using namespace std;
typedef struct data
{
const char* str;
}PERSON;
//线程函数
DWORD WINAPI Fun(LPVOID lpParamter)
{
PERSON* pmd = (PERSON*)lpParamter;
for (int i = 0; i < 10; i++)
{
cout << "魔镜魔镜谁最美: " << pmd->str << i << endl;
//Sleep(500); //这个很有意思
}
return 0;
}
int main()
{
PERSON str;
str.str = "当然是美丽的主人!";
HANDLE hThread = CreateThread(NULL, 0, Fun, &str, 0, NULL);
if (hThread != NULL) {
WaitForSingleObject(hThread, INFINITE); // 等待线程结束
CloseHandle(hThread);
hThread = NULL;
}
cout << "Child thread is over." << endl;
return 0;
}
这种方式了解一下就可以了,因为他是不安全的,为什么不安全,因为会有内存泄漏问题,如果你有求知欲,可评论,评论会回复你哦~~~