在Windows上使用线程.简单的例子?

我需要什么,如何在 Windows Vista上使用C中的线程?

你能给我一个简单的代码示例吗?

这是 MSDN sample关于如何在Windows上使用CreateThread().

基本思想是您调用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类型的初始化.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...