Windows Socket 编程有错误!那位圣人可以救小弟一命
帮帮小弟!~ 感激不尽!我的程序是在控制台应用程序下建的
Win32 Console Application
我想编写一个socket程序
//加载socket
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested=MAKEWORD(1,1);
err=WSAStartup(wVersionRequested,&wsaData);
if(err!=0)
{
return;
}
if(LOBYTE(wsaData.wVersion)!=1||
HIBYTE(wsaData.wVersion)!=1 )
{
WSACleanup();
return;
}
}
编译显示:
--------------------Configuration: SERVER - Win32 Debug--------------------
Compiling...
SERVER.CPP
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(5) : error C2065: 'WORD' : undeclared identifier
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(5) : error C2146: syntax error : missing ';' before identifier 'wVersionRequested'
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(5) : error C2065: 'wVersionRequested' : undeclared identifier
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(6) : error C2065: 'WSADATA' : undeclared identifier
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(6) : error C2146: syntax error : missing ';' before identifier 'wsaData'
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(6) : error C2065: 'wsaData' : undeclared identifier
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(9) : error C2065: 'MAKEWORD' : undeclared identifier
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(11) : error C2065: 'WSAStartup' : undeclared identifier
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(16) : error C2065: 'LOBYTE' : undeclared identifier
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(16) : error C2228: left of '.wVersion' must have class/struct/union type
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(17) : error C2065: 'HIBYTE' : undeclared identifier
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(17) : error C2228: left of '.wVersion' must have class/struct/union type
E:\程序开发项目\自编工程\SERVER\SERVER.CPP(19) : error C2065: 'WSACleanup' : undeclared identifier
Error executing cl.exe.
SERVER.exe - 13 error(s), 0 warning(s)
我包含拉头文件和连接库文件后
<winsock2.h> Link项添加 ws2_32.lib
#include <winsock2.h>
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested=MAKEWORD(1,1);
err=WSAStartup(wVersionRequested,&wsaData);
if(err!=0)
{
return;
}
if(LOBYTE(wsaData.wVersion)!=1||
HIBYTE(wsaData.wVersion)!=1 )
{
WSACleanup();
return;
}
}
编译显示:
--------------------Configuration: SERVER - Win32 Debug--------------------
Compiling...
SERVER.CPP
e:\程序开发项目\vc98\include\winnt.h(1092) : error C2146: syntax error : missing ';' before identifier 'KSPIN_LOCK'
e:\程序开发项目\vc98\include\winnt.h(1092) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
SERVER.exe - 2 error(s), 0 warning(s)
祝: 同学们身体健康!