简体   繁体   中英

'Hints' uses undefined struct - winSock

I am trying to build a basic application with winsock and I have ran into a problem. I have search through google extensivliy and took a look at the MSDN site but I still seem to be unable to solve this issue.

ERROR: Error C2079 'hints' uses undefined struct 'addrInfo'

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#pragma once
#include <iostream> 
#include <windows.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>   
#include "string.h"
#pragma comment(lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib") 
#pragma comment (lib, "AdvApi32.lib")


 int main()
 {
  int _iResult;
  struct addrInfo *result = NULL, *ptr = NULL, hints;
  _iResult = WSAStartup(MAKEWORD(2,2), &_wsaData);

  if(_iResult == 0)
  {
     ZeroMemory(&hints, sizeof(hints));
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
     hints.ai_protocol = IPPROTO_TCP;
     return "Window Socket DLL loaded...";
  }
  else
  {
     return "Failed to Window Socket DLL loaded...";
  }

 }

Any help would be appreciated.

struct addrInfo is not the same type as struct addrinfo . Your program uses the first, the headers define the second.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM