(C++) CreateThread

先理解一下函数原型:

HANDLE WINAPI CreateThread(
  _In_opt_  LPSECURITY_ATTRIBUTES  lpThreadAttributes, // 指向SECURITY_ATTRIBUTES结构的指针,用于决定返回的handle是否可以被子进程继承。如果是NULL,则handle不能不继承。
  _In_      SIZE_T                 dwStackSize,        // 栈的初始大小(in bytes),如果这个参数是0,则新的线程使用默认大小。
  _In_      LPTHREAD_START_ROUTINE lpStartAddress,     // 指向线程要执行的函数的指针。这个指针代表线程的起始地址。 
  _In_opt_  LPVOID                 lpParameter,        // 指向要传递给线程的参数。
  _In_      DWORD                  dwCreationFlags,    // 控制线程创建的一个标志位。 0 表示线程在创建后立即执行。
  _Out_opt_ LPDWORD                lpThreadId          // 指向收到线程ID的变量的指针,如果这个参数是NULL,那么线程ID没有返回。
);

返回值
如果函数运行成功,则返回一个指向新线程的handle。
如果失败,返回值为NULL,可以用GetLastError 来获取详细的错误信息。

参考:

http://cboard.cprogramming.com/cplusplus-programming/54830-sending-arguments-function-using-createthread.html

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682453(v=vs.85).aspx

A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpThreadAttributes is NULL, the handle cannot be inherited.

原文地址:https://www.cnblogs.com/fdyang/p/5075593.html