例程1:传递整型参数
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
DWORD WINAPI ThreadProFunc(LPVOID lpParam);
int main(int argc, char **argv)
{
HANDLE hThread;
DWORD dwThreadId;
int param = 20;
hThread = CreateThread( NULL, NULL, ThreadProFunc, ¶m , 0, &dwThreadId);
CloseHandle(hThread); //关闭线程句柄
system("pause");
return 0;
}
DWORD WINAPI ThreadProFunc(LPVOID lpParam)
{
printf("param = %d\n", *(int*)lpParam);
return 0;
}
运行结果:
param = 20
请按任意键继续. . .
例程2:传递字符串
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
DWORD WINAPI ThreadProFunc(LPVOID lpParam);
int main(int argc, char **argv)
{
HANDLE hThread;
DWORD dwThreadId;
char param[] = "hello";
hThread &#