title: Developing with WinSock2, error with CreateThread() function
body: <p>I begin to develop my tool, which works with net at the TCP level, and have got the following problem:</p>
  
  <ul>
  <li>Creating thread for <em>accept()</em> function of Winsock</li>
  </ul>
  
  <p>I have googled and looked for the references and evereywhere there is info about creating new thread:</p>
  
  <ul>
  <li>It must have DWORD WINAPI (unsigned long __stdcall) in prefix</li>
  <li>It must accept LPVOID argument</li>
  </ul>
  
  <p>And such function will be used as the 3rd argument in CreateThread() function as LPTHREAD_START_ROUTINE structure.</p>
  
  <p>But I have got the next error after compiling: </p>
  
  <p>(131) : error C2664: 'CreateThread' : cannot convert parameter 3 from 'DWORD (__stdcall Net::* )(LPVOID)' to 'LPTHREAD_START_ROUTINE'</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;Windows.h&gt;
  
  #pragma comment(lib, "Ws2_32.lib")
  
  typedef struct Header
  {
  friend struct Net;
  
  private:
      WORD wsa_version;
      WSAData wsa_data;
  
      SOCKET sock;
      SOCKADDR_IN service;
  
      char *ip;
      unsigned short port;
  
  public:
      Header(void)
      {
          wsa_version = 0x202;
  
          ip = "0x7f.0.0.1";
          port = 0x51;
  
          service.sin_family = AF_INET;
          service.sin_addr.s_addr = inet_addr(ip);
          service.sin_port = htons(port);
      }
  
  } Header;
  
  typedef struct Net
  {
  private:
      int result;
  
      void WSAInit(WSAData *data, WORD *wsa_version)
      {
          result = WSAStartup(*wsa_version, &amp;(*data));
  
          if(result != NO_ERROR)
          {
              std::cout &lt;&lt; "WSAStartup() failed with the error: " &lt;&lt; result &lt;&lt; std::endl;
          }
          else
          {
              std::cout &lt;&lt; (*data).szDescription &lt;&lt; " " &lt;&lt; (*data).szSystemStatus &lt;&lt; std::endl;
          }
      }
  
      void SocketInit(SOCKET *my_socket)
      {
          (*my_socket) = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  
          if((*my_socket) == INVALID_SOCKET)
          {
              std::cout &lt;&lt; "Socket initialization failed with the error: " &lt;&lt; WSAGetLastError() &lt;&lt; std::endl;
              WSACleanup();
          }
          else
          {
              std::cout &lt;&lt; "Socket initialization successful!" &lt;&lt; std::endl;
          }
      }
  
      void SocketBind(SOCKET *my_socket, SOCKADDR_IN *service)
      {
          result = bind((*my_socket), (SOCKADDR*)&amp;(*service), sizeof(*service));
  
          if(result == SOCKET_ERROR)
          {
              std::cout &lt;&lt; "Socket binding failed with the error: " &lt;&lt; WSAGetLastError() &lt;&lt; std::endl;
              closesocket((*my_socket));
              WSACleanup();
          }
          else
          {
              std::cout &lt;&lt; "Socket binding successful!" &lt;&lt; std::endl;
          }
  
          result = listen(*my_socket, SOMAXCONN);
  
          if(result == SOCKET_ERROR)
          {
              std::cout &lt;&lt; "Socket listening failed with the error: " &lt;&lt; WSAGetLastError() &lt;&lt; std::endl;
          }
          else
          {
              std::cout &lt;&lt; "Listening to the socket..." &lt;&lt; std::endl;
          }
      }
  
      void SocketAccept(SOCKET *my_socket)
      {
          SOCKET sock_accept = accept((*my_socket), 0, 0);
  
          if(sock_accept == INVALID_SOCKET)
          {
              std::cout &lt;&lt; "Accept failed with the error: " &lt;&lt; WSAGetLastError() &lt;&lt; std::endl;
              closesocket(*my_socket);
              WSACleanup();
          }
          else
          {
              std::cout &lt;&lt; "Client socket connected!" &lt;&lt; std::endl;
          }
  
          char data[0x400];
          result = recv(sock_accept, data, sizeof(data), 0);
      }
  
      DWORD WINAPI Threading(LPVOID lpParam)
      {
          SOCKET *my_socket = (SOCKET*)lpParam;
          SocketAccept(my_socket);
      }
  
  public:
      Net(void)
      {
          Header *obj_h = new Header();
  
          WSAInit(&amp;obj_h-&gt;wsa_data, &amp;obj_h-&gt;wsa_version);
  
          SocketInit(&amp;obj_h-&gt;sock);
          SocketBind(&amp;obj_h-&gt;sock, &amp;obj_h-&gt;service);
  
          HANDLE thrd = CreateThread(NULL, 0, &amp;Net::Threading, &amp;obj_h-&gt;sock, 0, NULL);
  
          delete &amp;obj_h;
      }
  } Net;
  
  int main(void)
  {
      Net *obj_net = new Net();
  
      delete &amp;obj_net;
  
      return 0;
  }
  </code></pre>