socket编程声明就出错,有劳定位下,辛苦了

zhaolixin007 2010-06-22 03:17:54
#include "winsock2.h"//add by zhaolixin here
#pragma comment(lib,"ws2_32.lib")//add by zhaolixin here

在函数::InitInstance()中填写的语句如下
WSADATA wsd;//add by zhaolixin here
WSAStartup(MAKEWORD(2,2),&wsd);//add by zhaolixin end

提示如下错误:
Compiling...
ZQQ.cpp
F:\DD\ZQQ\ZQQ.cpp(47) : error C2065: 'WSADATA' : undeclared identifier
F:\DD\ZQQ\ZQQ.cpp(47) : error C2146: syntax error : missing ';' before identifier 'wsd'
F:\DD\ZQQ\ZQQ.cpp(47) : error C2065: 'wsd' : undeclared identifier
F:\DD\ZQQ\ZQQ.cpp(48) : error C2065: 'WSAStartup' : undeclared identifier
Error executing cl.exe.

ZQQ.exe - 4 error(s), 0 warning(s)



...全文
127 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shark0309 2010-06-22
  • 打赏
  • 举报
回复
WORD wVersionRequested;
WSADATA wsaData;
int err;

wVersionRequested = MAKEWORD( 2, 2 );

err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}

/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */

if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
WSACleanup( );
return;
}

#include <Winsock2.h>
#pragram comment(lib, "Ws2_32.lib")
shenyi0106 2010-06-22
  • 打赏
  • 举报
回复
检查一下
如果工程里存在afxsock.h的话
就把winsock2.h和另一个(我不记得名字了)有关socket的头文件去掉
Eleven 2010-06-22
  • 打赏
  • 举报
回复
#include "winsock2.h"//add by zhaolixin here
#pragma comment(lib,"ws2_32.lib")//add by zhaolixin here
---------------------------------------------------------
这个你加在哪里???
Shrek_MyCpp 2010-06-22
  • 打赏
  • 举报
回复
然后,就可以直接使用socket的接口函数了。
Shrek_MyCpp 2010-06-22
  • 打赏
  • 举报
回复
在stdafx.h中,加入#include <afxsock.h>

在cpp文件中,调用AfxOleInit()
xfill 2010-06-22
  • 打赏
  • 举报
回复
#include <winsock2.h>

#pragram comment(lib, "Ws2_32.lib")

加在 stdafx.h 最后面

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧