Advertisement

Some Stupid Error

Started by May 18, 2003 03:58 PM
5 comments, last by SumDude 21 years, 8 months ago
Everytime i try to compile my code in MSVC++ 6.0 while trying to use my include it gives me this error "Cannot open include file: ''SocketClass.h'': No such file or directory". And what makes me angry is that the file is in the same workspace and it should be working.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                          
Looking for video game music? Check out some of my samples at http://www.youtube.c...ser/cminortunes            
                                                          
I'm currently looking to create music for a project, if you are interested e-mail me at cminortunes@gmail.com    
                                                          
Please only message me for hobby projects, I am not looking to create music for anything serious.
If you gave less details about the problem, we would have an even clearer idea of how to help you.
Advertisement
You are using
#include "SocketClass.h" 

and not
#include <SocketClass.h> 

right?





Well heres the code for it.


SocketClass Header
----------------------
#ifndef SocketClass_H
#define SocketClass_H
#ifdef SocketClass_H


#include <winsock2.h>
#include <conio.h>



class SocketClass
{
private:
public:
SOCKET Socket;
SocketClass();
~SocketClass();
int Bind(int iPort);
void Disconnect();
int Listen();
bool Connect(char *strServerAddress, int iPort);
bool Accept(SocketClass &scSocket);
int Recv(char *strBuffer, int iBufLen, int iFlags);

int Send(char *strBuffer, int iBufLen, int iFlags);

};

#endif

SocketClass.cpp
---------------------------------------

#include "SocketClass.h"


int SocketClass::Bind(int iPort)
{
sockaddr_in ServerAddress;

Socket = socket(AF_INET, SOCK_STREAM, 0);
if(Socket == INVALID_SOCKET)
{
return false;
}

memset(&ServerAddress, 0, sizeof(sockaddr_in));
ServerAddress.sin_family = AF_INET;
ServerAddress.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
ServerAddress.sin_port = htons(iPort);
if(bind(Socket, (sockaddr*) &ServerAddress, sizeof(sockaddr)) == SOCKET_ERROR)
{
Disconnect();
return false;
}
else
return true;
}

SocketClass::SocketClass()
{
WSADATA wsaDATA;
WORD wVersion;

wVersion = MAKEWORD(2,0);
Socket = INVALID_SOCKET;
iStatus = WSAStartup(wVersion, wsaDATA);
}

SocketClass::~SocketClass()
{
Disconnect();
}

void SocketClass::Disconnect()
{
if(Socket != INVALID_SOCKET)
{
closesocket(Socket);
Socket = INVALID_SOCKET;
}
}

int SocketClass::Listen()
{
return listen(Socket, 32);
}

bool SocketClass::Accept(SocketClass *scSocket)
{
sockaddr_in saClient;
int iClientS = sizeof(sockaddr_in);

scSocket.Socket = accept(Socket, (struct sockaddr*)&saClient, &iClient);
if(scSocket.Socket == INVALID_SOCKET)
{
return false;
}
else
{
return true;
}
}

bool SocketClass::Connect(char strServerAddress, int iPort)
{
struct sockaddr_in server;
LPHOSTENT host;
int err;

Socket = socket(AF_INET, SOCK_STREAM, 0);
if(Socket == INVALID_SOCKET)
{
return false;
}

memset(&server,0, sizeof(sockaddr_in));
server.sin_family = AF_INET;
server.sin_addr.S_un.S_addr = inet_addr(strServerAddress);
if(server.sin_addr.S_un.S_addr == INADDR_NONE)
{
host = gethostbyname(strServerAddress);
if(host != NULL)
server.sin_addr.S_un.S_addr = ((LPIN_ADDR)host->h_addr_list)->S_un.S_addr;

else
{
return false;
}
}

server.sin_port = htons(iPort);
err = connect(Socket, (struct sockaddr *) &serverm sizeof(sockaddr));

if(err == SOCKET_ERROR)
{
Disconnect();
return false;
}
return true;
}

int SocketClass::Send(char *strBuffer, int iBufLen, int iFlags)
{
return send(Socket, strBuffer, iBufLen, iFlags);
}

int SocketClass::Recv(char *strBuffer, int iBufLen, int iFlags)
{
return recv(Socket, strBuffer, iBufLen, iFlags);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                          
Looking for video game music? Check out some of my samples at http://www.youtube.c...ser/cminortunes            
                                                          
I'm currently looking to create music for a project, if you are interested e-mail me at cminortunes@gmail.com    
                                                          
Please only message me for hobby projects, I am not looking to create music for anything serious.
I don''t know if it will help your "file not found" problem, but remove this line (or else you need another #endif):
#ifdef SocketClass_H 



  /*Also, next time put your code in a source box!Just put  and [ / s o u r c e ] around the code.<br>(Without the spaces, of course)<br>*/</font><br>  </pre></DIV><!–ENDSCRIPT–>     




SocketClass Header
----------------------
#ifndef SocketClass_H
#define SocketClass_H
#ifdef SocketClass_H <- this is not effective codes in your files, remove this.


Advertisement
Ok, the previous statements were correct; it''s not very efficient to put that other ''#ifdef'' in there. Another thing is, make sure the header file is in the same folder. VC++ works off file names, and paths, NOT workspaces! Be sure to use relative paths, like if the main.cpp is in ''C:/'' and header.h is in ''C:/Data/'', use the following include:

#include "data/header.h"

Good luck!

Chris Pergrossi
< ctoan >
My Realm
Chris Pergrossi< ctoan >My Realm

This topic is closed to new replies.

Advertisement