2007年12月7日星期五

CreateThread

例1:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char a[255];
strcpy(a,"qinwei");
DWORD dwThreadId;
CreateThread(NULL,0,ClientThread,(LPVOID)a,0,&dwThreadId);
}
DWORD WINAPI ClientThread(LPVOID lpParam)
{
char* a = (char* )lpParam;
ShowMessage(a);// <------------通过
return 0;
}

例2:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
POINT a;
DWORD dwThreadId;
a.x=7;
CreateThread(NULL,0,ClientThread,(LPVOID)&a,0,&dwThreadId);
}
DWORD WINAPI ClientThread(LPVOID lpParam)
{
POINT* a = (POINT* )lpParam;
ShowMessage(a->x);// <------------出错
return 0;
}

没有评论: