Author | Message | Time |
---|---|---|
bethra | I made a class that creates a socket and has a few functions using the socket created in the class. However the compiler compiles the classes header file and it's source file without any problems/errors. However when I try to use the class I get this error that I can't seem to get rid of... I've tried fixing it, I even rewrote atleast half of the class... Here is what the compiler doesn't like. I copy and pasted it and put a blank like to separate each one: [quote] Main warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification Main error LNK2019: unresolved external symbol "public: char * __thiscall SocketBNCS::RecvBNCS(void)" (?RecvBNCS@SocketBNCS@@QAEPADXZ) referenced in function "public: int __thiscall Logon::StartLogon(char *,unsigned short,char *,unsigned short)" (?StartLogon@Logon@@QAEHPADG0G@Z) Main error LNK2019: unresolved external symbol "public: int __thiscall SocketBNCS::SendBNCS(char *)" (?SendBNCS@SocketBNCS@@QAEHPAD@Z) referenced in function "public: int __thiscall Logon::LogonSequence(void)" (?LogonSequence@Logon@@QAEHXZ) Main fatal error LNK1120: 2 unresolved externals [/quote] Here is the "SocketBNCS" class that is causing the error I believe: [code] // SocketBNCS.cpp // #include <winsock2.h> #include <windows.h> #include <malloc.h> #include <stdlib.h> #include <stdio.h> #include "PacketBuffer.h" #include "PacketDebuffer.h" #include "Misc.h" #include "SocketBNCS.h" //============================= // constructor SocketBNCS::SocketBNCS(){ error = NET_OK; } //============================= // sets the created socket void SocketBNCS::SetSockBNCS(SOCKET bncsSocket){ sBNCS = bncsSocket; error = NET_OK; } //===================================================== // connect bncs socket int SocketBNCS::ConnectBNCS(LPSTR hostname, WORD portnum){ WORD sckver; WSADATA wsaData; LPHOSTENT hostEntry; SOCKADDR_IN serverInfo; int error; sckver = MAKEWORD(2, 2); WSAStartup(sckver, &wsaData); if (isdigit(hostname[0]) != 0){ in_addr iaHost; iaHost.s_addr = inet_addr(hostname); hostEntry = gethostbyaddr((const char*)&iaHost, sizeof(struct in_addr), AF_INET); }else{ hostEntry = gethostbyname(hostname); } // if error when making hostEntry if(!hostEntry){ error = WSAGetLastError(); ReportErr(error, "gethostbyname()"); WSACleanup(); return NET_ERR; } // create the BNLS socket and check error sBNCS = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); // if error making socket if(sBNCS == INVALID_SOCKET){ error = WSAGetLastError(); ReportErr(error, "WSASocket()"); WSACleanup(); return NET_ERR; } // fill in the SOCKADDR_IN struct info serverInfo.sin_family = AF_INET; serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list); serverInfo.sin_port = htons((u_short)portnum); // Connect to the server error = connect(sBNCS, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr)); if (error == SOCKET_ERROR) { error = WSAGetLastError(); ReportErr(error, "connect()"); WSACleanup(); return NET_ERR; } // Successfully connected! printf("[BNET] Connected.\n"); return NET_OK; } //===================================================== // send bncs packet inline int SocketBNCS::SendBNCS(LPSTR buff){ int nBytes; int nret; BYTE packID; packID = getID(buff, _msize(buff)); DebugOutput(buff, _msize(buff), 2, packID); nBytes = send(sBNCS, buff, _msize(buff), 0); nret = WSAGetLastError(); switch (nBytes) { case SOCKET_ERROR: printf("[SEND] Failed.\n\n"); return NET_ERR; default: //printf("Message Sent.\n\n"); return NET_OK; } } //===================================================== // recv bncs packet inline LPSTR SocketBNCS::RecvBNCS(){ int nBytes; BYTE packID; LPSTR tempbuf = new char[512]; // or on the heap nBytes = recv(sBNCS, tempbuf, 512, // Complete size of buffer 0); switch (nBytes) { case SOCKET_ERROR: printf("SOCKET Error.\n\n"); delete [] tempbuf; return "Err"; case 0: printf("[RECV] Nothing.\n\n"); delete [] tempbuf; return "Err"; default: //printf("Message Recieved.\n\n"); packID = getID(tempbuf, nBytes); DebugOutput(tempbuf, nBytes, 1, packID); if((tempbuf = (char*)realloc(tempbuf, ((nBytes)))) == NULL){ printf("Error: Unable to reallocate/resize recieved buffer" ); return "Err"; } return tempbuf; } } //===================================================== // report socket error inline void SocketBNCS::ReportErr(int errcode, LPSTR funcerr){ char errMsg[92]; ZeroMemory(errMsg, 92); sprintf(errMsg, "Call to %s returned error %d!", (char*)funcerr, errcode); } //===================================================== // close bncs socket void SocketBNCS::CloseBNCS(){ closesocket(sBNCS); WSACleanup(); printf("[BNET] Disconnected.\n"); } //====================================================== // destructor SocketBNCS::~SocketBNCS(){ } [/code] Now, I am using this class "SocketBNCS" class in a different class named "Logon". Here is a example the code that seems to be causing the problem: [code] LPSTR buf; SocketBNCS SckBNCS; // this is an example of using SendBNCS and is one error if((buf = SBNCS.RecvBNCS()) != 0) { // Ignore this, this is not a cause of any of the errors DebugOutput(buf, _msize(buf)); } // this is an example of using RecvBNCS and is one error if(SckBNCS.SendBNCS(buf) == NET_OK) { // Ignore this, this is not a cause of any of the errors DebugOutput(buf, _msize(buf)); } [/code] help prz. | January 27, 2005, 8:52 PM |