| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu Jun 12, 2008 8:22 am Post subject: winsock errors |
|
|
I'm learning winsock from msdn.com and so I've been using their code up to about the accepting a connection from a client and I tried to compile and I got a bunch of linking errors. I think it has to do with WS2_32.lib. But it's in the SDK's Lib folder, and I have my VC++ Directories pointing at that folder in the Lib section. I don't think it's my code, but just incase.
| Code: |
#include <winsock2.h>
#include <ws2tcpip.h>
#define DEFAULT_PORT "27015"
int main() {
WSADATA wsaData;
int Result = WSAStartup(MAKEWORD(2, 2), &wsaData);
if(Result != 0) {
return 0;
}
struct addrinfo *result = NULL, *ptr = NULL, hints;
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;
Result = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result);
if(Result != 0) {
WSACleanup();
return 1;
}
SOCKET ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if(ListenSocket == INVALID_SOCKET) {
freeaddrinfo(result);
WSACleanup();
return 1;
}
Result = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);
if(Result == SOCKET_ERROR) {
freeaddrinfo(result);
closesocket(ListenSocket);
WSACleanup();
return 1;
}
if(listen(ListenSocket, SOMAXCONN) == SOCKET_ERROR) {
closesocket(ListenSocket);
WSACleanup();
return 1;
}
return 0;
}
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Renkokuken GO Moderator
Reputation: 4
Joined: 22 Oct 2006 Posts: 3249
|
Posted: Thu Jun 12, 2008 8:28 am Post subject: |
|
|
| It'd be nice to provide the "bunch of linking errors."
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Jun 12, 2008 8:29 am Post subject: |
|
|
| Code: | | #pragma comment ( lib, "Ws2_32.lib" ) |
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu Jun 12, 2008 8:33 am Post subject: |
|
|
Ok, I still get two errors though.
| Code: |
------ Build started: Project: winsock, Configuration: Debug Win32 ------
Linking...
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\winsock\Debug\winsock.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\winsock\winsock\Debug\BuildLog.htm"
winsock - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Renkokuken GO Moderator
Reputation: 4
Joined: 22 Oct 2006 Posts: 3249
|
Posted: Thu Jun 12, 2008 8:36 am Post subject: |
|
|
| It looks like you're using a console's entry point on a win32 windows application. Either change subsystem to console, or use WinMain.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu Jun 12, 2008 8:39 am Post subject: |
|
|
Thank's Renko. It's working now.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Renkokuken GO Moderator
Reputation: 4
Joined: 22 Oct 2006 Posts: 3249
|
Posted: Thu Jun 12, 2008 8:40 am Post subject: |
|
|
| Glad to help.
|
|
| Back to top |
|
 |
|