I cannot for the life of me see where i'm going wrong.
I've got a winsock class, the SOCKET is defined in the Header, but when I try to use it in a function I get a first exception crash. It's ground me to a halt (btw, for anyone who saw the other thread, I solved my win32 wrapper problem).
Code:
//Header://
#ifndef _WINSOCKCLASS_H_
#define _WINSOCKCLASS_H_
#define _WINSOCKAPI_
#include <WinSock2.h>
#include <String>
#include <Windows.h>
class winSockClass
{
public:
winSockClass();
~winSockClass();
bool AsyncSelect( HWND lHwnd );
bool Startup();
bool wsConnect(std::string URL, int lPort);
bool SendMsg(std::string message, LPARAM lParam);
bool Shutdown();
std::string lServer;
int lPort;
private:
SOCKET lSocket;
SOCKADDR_IN sockAddr;
WSADATA wsaDat;
struct hostent *host;
};
#endif _WINSOCKCLASS_H_
// CPP: //
#define _WINSOCKAPI_
#include "winSockClass.h"
#include <WinSock2.h>
#include <vector>
#pragma comment(lib, "ws2_32.lib")
winSockClass::winSockClass()
{
lSocket = NULL;
}
winSockClass::~winSockClass() {}
bool winSockClass::Startup()
{
WSADATA wsaa;
int nResult = WSAStartup(MAKEWORD(2,2), &wsaa);
if(nResult != 0)
{
return false;
}
lSocket = socket( AF_INET, SOCK_STREAM, 0 ); // <<--- crash here.
if( lSocket == INVALID_SOCKET )
{
return false;
}
return true;
}