--------------------Configuration: ctl_one - Win32 Debug--------------------
Compiling...
ctl_one.c
Linking...
ctl_one.obj : error LNK2001: unresolved external symbol _ReportError
Debug/ctl_one.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
ctl_one.exe - 2 error(s), 0 warning(s)
===========
here's my code
Code:
#include <windows.h>
#pragma comment(lib, "wsock32.lib")
#include <winsock.h>
#include <stdio.h>
#define NETWORK_ERROR -1
#define NETWORK_OK 0
void ReportError(int, const char *);
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) {
WORD sockVersion;
WSADATA wsaData;
int nret;
SOCKET listeningSocket;
SOCKADDR_IN serverInfo;
SOCKET theClient;
sockVersion = MAKEWORD(1, 1); // We'd like Winsock version 1.1
// We begin by initializing Winsock
WSAStartup(sockVersion, &wsaData);
// Next, create the listening socket
listeningSocket = socket(AF_INET, // Go over TCP/IP
SOCK_STREAM, // This is a stream-oriented socket
IPPROTO_TCP); // Use TCP rather than UDP
if (listeningSocket == INVALID_SOCKET) {
nret = WSAGetLastError(); // Get a more detailed error
ReportError(nret, "socket()"); // Report the error with our custom function
WSACleanup(); // Shutdown Winsock
return NETWORK_ERROR; // Return an error value
}
// Use a SOCKADDR_IN struct to fill in address information
serverInfo.sin_family = AF_INET;
serverInfo.sin_addr.s_addr = INADDR_ANY; // Since this socket is listening for connections,
// any local address will do
serverInfo.sin_port = htons(8888); // Convert integer 8888 to network-byte order
// and insert into the port field
// Bind the socket to our local server address
nret = bind(listeningSocket, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr));
if (nret == SOCKET_ERROR) {
nret = WSAGetLastError();
ReportError(nret, "bind()");
WSACleanup();
return NETWORK_ERROR;
}
// Make the socket listen
nret = listen(listeningSocket, 10); // Up to 10 connections may wait at any
// one time to be accept()'ed
if (nret == SOCKET_ERROR) {
nret = WSAGetLastError();
ReportError(nret, "listen()");
WSACleanup();
return NETWORK_ERROR;
}
// Wait for a client
while(1)
{
theClient = accept(listeningSocket,
NULL, // Address of a sockaddr structure (see explanation below)
NULL); // Address of a variable containing size of sockaddr struct
if (theClient == INVALID_SOCKET) {
nret = WSAGetLastError();
ReportError(nret, "accept()");
WSACleanup();
return NETWORK_ERROR;
}
else if ("1" == "1")
{}
listeningSocket = theClient;
break;
}
// Send and receive from the client, and finally,
closesocket(theClient);
closesocket(listeningSocket);
// Shutdown Winsock
WSACleanup();
return NETWORK_OK;
}
anyone knows what's wrong?
using vc++6.0