| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 878 人关注过本帖
标题:求助!winsocket的问题
只看楼主 加入收藏
lofe811
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-11-11
收藏
 问题点数:0 回复次数:3 
求助!winsocket的问题

编了一个程序出现下面错误:

Linking...
MCServer.obj : error LNK2001: unresolved external symbol _accept@12
MCServer.obj : error LNK2001: unresolved external symbol _listen@8
MCServer.obj : error LNK2001: unresolved external symbol _bind@12
MCServer.obj : error LNK2001: unresolved external symbol _htons@4
MCServer.obj : error LNK2001: unresolved external symbol _closesocket@4
MCServer.obj : error LNK2001: unresolved external symbol _WSAAsyncSelect@16
MCServer.obj : error LNK2001: unresolved external symbol _WSACleanup@0
MCServer.obj : error LNK2001: unresolved external symbol _socket@12
MCServer.obj : error LNK2001: unresolved external symbol _WSAStartup@8
Debug/MCServer.exe : fatal error LNK1120: 9 unresolved externals
Error executing link.exe.

请问是怎么回事啊????

谢谢!!!!!!!!!!!!!!!!!!1
代码是:

#include <windows.h>

#define SERVER_PORT 1111
#define WM_SOCKET (WM_USER+1)

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpcmdLine, int nCmdShow)
{
static TCHAR szAppName[]= TEXT("ChatServer");
static TCHAR szClassName[]= TEXT("ChatServerClass");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;

wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wndclass.hCursor = LoadCursor( NULL,IDC_ARROW );
wndclass.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szClassName;

if ( !RegisterClass( &wndclass ) )
{
MessageBox( NULL, TEXT("This program requires Windows NT!"),
szAppName, MB_ICONERROR );

return 0;
}

hwnd = CreateWindow( szClassName, TEXT("Simple WinSock Chat Servere"),
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL );

ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );

while ( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HINSTANCE hInstance;
int nSize;
WSADATA WSAData;
static struct sockaddr_in server,from;
static SOCKET local_server, local_listen;
int nError;
WORD wEvent, wError;
static TCHAR szReceive[1024];
static TCHAR szSend[1024];

switch( message )
{
case WM_CREATE:
hInstance = (HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE );


if( nError = WSAStartup( MAKEWORD(2,0), &WSAData ) )
{
MessageBox( hwnd, "WinSock Startup Error!", "Server", MB_ICONERROR | MB_OK );
return TRUE;
}

local_server = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if( local_server == INVALID_SOCKET )
{
MessageBox( hwnd, "Socket Creation Error!", "Server", MB_ICONERROR | MB_OK );

WSACleanup();
return TRUE;
}

if( SOCKET_ERROR == WSAAsyncSelect( local_server, hwnd,
WM_SOCKET, FD_ACCEPT | FD_READ ) )
{
MessageBox( hwnd, "WSAAsyncSelect Error!", "Server", MB_ICONERROR | MB_OK );

closesocket( local_server );
WSACleanup();
return TRUE;
}

server.sin_family = AF_INET;
server.sin_port = htons( SERVER_PORT );
if( SOCKET_ERROR == bind( local_server, (struct sockaddr *)&server, sizeof(server) ) )
{
MessageBox( hwnd, "Bind Error!", "Server", MB_ICONERROR | MB_OK );

closesocket( local_server );
WSACleanup();
return TRUE;
}

listen( local_server, 5 );
return 0;

case WM_SIZE:
return 0;

case WM_SOCKET:
wEvent = WSAGETSELECTEVENT(lParam);
wError = WSAGETSELECTERROR(lParam);

switch( wEvent )
{
case FD_ACCEPT:
if( wError )
{
MessageBox( hwnd, "Accept Error!", "Server", MB_ICONERROR | MB_OK );
return 0;
}

nSize = sizeof(from);
local_listen = accept( local_server, (struct sockaddr *)&from, &nSize );

return 0;

case FD_READ:
if( wError )
{
MessageBox( hwnd, "Read Error!", "Server", MB_ICONERROR | MB_OK );
return 0;
}

return 0;
}
return 0;

case WM_SETFOCUS:
return 0;

case WM_COMMAND:
return 0;

case WM_DESTROY:
closesocket( local_server );
closesocket( local_listen );
WSACleanup();

PostQuitMessage( 0 );
return 0;
}

return DefWindowProc( hwnd, message, wParam, lParam );
}


搜索更多相关主题的帖子: obj symbol MCServer winsocket 
2005-12-03 19:15
踏魔狼
Rank: 6Rank: 6
等 级:贵宾
威 望:24
帖 子:1322
专家分:33
注 册:2005-9-22
收藏
得分:0 
单看错误提示好象还有什么文件没有inculde。或者是没有external。

=×&D o I p R e E n C g T l X&×=
2005-12-05 09:34
kakaaka
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-5-2
收藏
得分:0 
把WS2_32.LIB连接进去没
2005-12-21 16:08
nonsenser
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-11-27
收藏
得分:0 

加了:
#pragma comment(lib,"ws2_32.lib")
之后:
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

test.exe - 2 error(s), 0 warning(s)
但是加了winsock2.h之后不知道为什么出了更多的莫名其妙的错误,不知道为什么,高手指点一下

[此贴子已经被作者于2005-12-23 14:12:57编辑过]

2005-12-23 14:11
快速回复:求助!winsocket的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.095434 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved