这是
MSDN sample关于如何在Windows上使用CreateThread().
原文链接:https://www.f2er.com/windows/365478.html基本思想是您调用CreateThread()并传递一个指向你的线程函数的指针,这是在目标线程创建后将会运行的.
最简单的代码是:
#include <windows.h> DWORD WINAPI ThreadFunc(void* data) { // Do stuff. This will be the first function called on the new thread. // When this function returns,the thread goes away. See MSDN for more details. return 0; } int main() { HANDLE thread = CreateThread(NULL,ThreadFunc,NULL,NULL); if (thread) { // Optionally do stuff,such as wait on the thread. } }
您也可以选择调用SHCreateThread()相同的基本思想,但是如果您要求它(如初始化COM)等会为您执行一些shell类型的初始化.