I finally got winsock code to compile by compiling it as a windows project.. as opposed to c++ source.
I successfully added the llibws2_32.a by going to Project-> Project Options -> parameters, but after compilation execution is terminated.. why???
Code:
#include<iostream>
#include<winsock2.h>
using namespace std;
int main()
{
WSADATA wsd;
WSAPROTOCOL_INFO *proto;
LPDWORD bufferlength = 0;
if(WSAStartup(MAKEWORD(2,2), &wsd) != 0)
cout << "\n\aWSAStartup failed.";
else
cout << "\n\nUsing winsock version " << wsd.wVersion;
/*
//This call will fail, but will return the correct buffer size
WSAEnumProtocols(NULL, NULL, bufferlength);
//Allocate the correct buffer size of WSAPROTOCOL_INFO structures
proto = new WSAPROTOCOL_INFO[*bufferlength];
//Populate an array of system protocols
WSAEnumProtocols(NULL, proto, bufferlength);
//Step through the array and view some system supported protocol information
for(int i=0; i<*bufferlength; i++)
{
cout << "\n\n\nVersion: " << proto[i].iVersion;
cout << "\nAddress Family: " << proto[i].iAddressFamily;
cout << "\nMax Sockets: " << proto[i].iMaxSockAddr;
cout << "\nMin Sockets: " << proto[i].iMinSockAddr;
cout << "\nProtocol: " << proto[i].szProtocol;
}
*/
cout << "Press [ENTER] to continue...";
cin.get();
WSACleanup();
return 0;
}
compiler log:
Code:
Compiler: Default compiler
Building Makefile: "F:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "F:\Dev-Cpp\Makefile.win" all
make.exe: Nothing to be done for `all'.
Execution terminated
Compilation successful