// MultipleThreadParam.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <afx.h>
DWORD WINAPI ThreadFun1(LPVOID lpParam)
{
printf("Welcome to ThreadFun1.\n");
int* ipNum = (int*)lpParam; //类型转换,无论什么类型都可以通过这种方式转换后使用
printf("The number is: %d\n",*ipNum);
*ipNum = 2;
return 0;
}
int main(int argc, char* argv[])
{
printf("Welcome to main.\n");
int iNum = 1;
printf("The number is: %d\n",iNum);
HANDLE handle = CreateThread(NULL, 0, ThreadFun1, &iNum, 0, NULL); //第4个参数为你需要的入参的地址,这里为&iNum
Sleep(10); //等线程起来,必须有的
printf("The number is: %d\n",iNum);
CloseHandle(handle);
return 0;
}
VC++多线程单个参数传递
最新推荐文章于 2021-10-16 19:13:15 发布