本篇文章为大家展示了C++中如何使用CreateThread参数,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
先定义要传递的C++ CreateThread参数结构体:
typedef struct SParam
{
int No;
unsigned short chnlID;
unsigned short sessionID;
}uParam,*sParam;
DWORD WINAPI AccountManagerPVOID pParam);
void main)
{
DWORD dwThreadId;
HANDLE hThrd = NULL; // thread handle
SParam sparam;
SParam *p;
sparam.No = 1;
sparam.chnlID = 1;
sparam.sessionID = 1;
p = &sparam;
hThrd = HANDLE)CreateThreadNULL,
0,
AccountManager,
p,
0,
dwThreadId;
}
DWORD WINAPI AccountManagerPVOID pParam)
{
sParam sparam;
sparam = sParam)pParam;
try
{
/*Run为自己写的一个方法,Runint i,unsigned short
chnlID,unsigned short sessionID)*/Runsparam->No,sparam->chnlID,sparam->sessionID);
}
catch ...)
{
logger.error"AccountManager%d): System error.\r\n", threadId);
}
}