#include"stdafx.h"#include<stdio.h>#include<windows.h>#include<stdlib.h>structthreadparameter{Charuser[ -]; Charname[ -];};D WORD WINAPI threadfunction (lpvoid pparam) {threadparameter*TP = (Threadparameter *) Pparam;//Cast Parameters Charuser[ -]; Charpass[ -]; strcpy (USER,TP-user); strcpy (PASS,TP-name); printf ("User =%s Pass =%s \ r \ n", User,pass); return 0;}intMainintargcChar*argv[]) {threadparameter TP; if(ARGC <3) {printf ("Unkow Options error.\r\n"); return-1; } memset (Tp.name,0, -); memset (Tp.user,0, -); strcpy (tp.user,argv[1]); strcpy (tp.name,argv[2]); HANDLE Threadhandle= CreateThread (NULL,0, (Lpthread_start_routine) THREADFUNCTION,&TP,0, NULL); if(Threadhandle = =Invalid_handle_value) {printf ("Create thread error.\r\n"); return-1; } WaitForSingleObject (Threadhandle,infinite); //waiting for thread to exitCloseHandle (Threadhandle);//Close Handle return 0;}
CreateThread creating thread-passing struct-body parameters