Solved

Win32 network programming in VC++ 6

Posted on 2002-07-04
10
340 Views
Last Modified: 2011-08-18
I wanna write some networking jazz in VC++ (tho mostly just plain ol' C), which appears to require me to use mostly winsock calls. However, when I use examples I keep finding from books and tutes, I keep getting errors for all the networking calls. Below is the output. I get the same results using winsock.h or winsock2.h. The files do exist in the include directory under VC98. I think I have something set up wrong, but I have no idea what it would be. If the header files are (already) there, shouldn't VC be ready to go with it? I haven't changed the Winsock headers or anything, so that shouldn't be a problem. I tried deleting the files that VC generates (like server.obj) to see if they were just messed up and needed to be forced to be rebuilt, but no dice. Anybody know what's wrong or have any ideas? thanks and ttyl,

mich

--------------------Configuration: server_console - Win32 Debug--------------------
Compiling...
server.c
Linking...
server.obj : error LNK2001: unresolved external symbol _listen@8
server.obj : error LNK2001: unresolved external symbol _closesocket@4
server.obj : error LNK2001: unresolved external symbol _bind@12
server.obj : error LNK2001: unresolved external symbol _socket@12
server.obj : error LNK2001: unresolved external symbol _htons@4
server.obj : error LNK2001: unresolved external symbol _gethostbyname@4
server.obj : error LNK2001: unresolved external symbol _gethostname@8
server.obj : error LNK2001: unresolved external symbol _accept@12
Debug/server_console.exe : fatal error LNK1120: 8 unresolved externals
Error executing link.exe.

server_console.exe - 9 error(s), 0 warning(s)
0
Comment
Question by:phirephly
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7131208
Just including the header file won't work--you need to include the LIBRARY file containing the code for the functions you're intending to call. In the case of WinSock this would probably be WSOCK32.LIB, so you need to add this library to the list of libraries which will be linked to your application.
0
 

Author Comment

by:phirephly
ID: 7131344
will give it a whirl tomorrow during the day. I bet you're right... I'm so stupid :p
0
 

Expert Comment

by:weicco
ID: 7131347
Library's name is ws2_32.lib in Windows 98, NT, 2000 and XP. In CE it is winsock.lib.
0
 

Expert Comment

by:Mrxlazuardin
ID: 7132687
Use WSOCK32.LIB in your Link Library Setting.
0
 

Author Comment

by:phirephly
ID: 7133055
I started usin' wsock32.lib, then ws2_32.lib last night and all my problems went away... what's the difference between the two? I'm guessing ws2_32 is for winsock 2, and wsock32 is for winsock 1? I believe I saw somewhere last night that said that WS2 is backwards compatible, so would include WS1 stuff, is that correct? But then ws2 would also have the new stuff, so would ws2 be the better one (and thus make weicco the correct answer?) or should it be wsock32 after all, as nibbs suggested? thanks and ttyl,

mich

PS - sorry, I haven't been able to post this forever... I've been havin' a really hard time gettin' the server to respond!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:phirephly
ID: 7133056
nibbs already said that.
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7133617
If they both work with all the functions you're actually using, either answer is good enough, I'd say.
0
 

Accepted Solution

by:
weicco earned 100 total points
ID: 7135802
Copy&Paste from MSDN:

  Header: Declared in winsock2.h.
  Import Library: Link with ws2_32.lib.

In Windows CE winsock.h and winsock.lib
0
 

Expert Comment

by:dhanaspace1
ID: 7145854
have called the WSAStartup??
 
0
 

Author Comment

by:phirephly
ID: 7146949
So ws2_32.lib is the one to use. thanks everyone!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now