Home  >  Q&A  >  body text

C++ createthread怎么传递多个参数?

线程函数:

DWORD WINAPI socket2(LPVOID lpp)
{
    SOCKET s = ((RECVPARAM*)lpp)->ServerSocket;
    //do morething...
    return 0;
}

创建线程:

struct RECVPARAM
{
    SOCKET ClientSocket;
    SOCKET ServerSocket;
};
RECVPARAM* svc; //这个svc的值是一大堆函数生成的,这里就不贴了
DWORD tid;
RECVPARAM th2 = {svc->ServerSocket,svc->ClientSocket};
int x = "0"; //我还想把这个x传给socket2函数
HANDLE h2 = CreateThread(0,0,socket2,&th2,0,&tid);

请问在CreateThread单独时候怎么把X也传给socket2函数?

新手 大神轻喷

PHP中文网PHP中文网2765 days ago643

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-17 15:09:23

    Solved, just redefine a structure

    reply
    0
  • Cancelreply