Hi, I have encountered error LNK2019 and LNK2005 issues. I had designed basically a .Lib file and tried to access the file through a normal console application.
the details of the Lib file:
(.h file)
#ifndef VNS_Lib_H_
#define VNS_Lib_H_
#pragma comment(lib,"ws2_32.lib") //Winsock Library
#include <WinSock2.h>
#include <errno.h>
#include <windows.h>
#include <process.h>
#include <algorithm>
#define LOC_ERRNO errno
bool threadFinished = false;
namespace WAVE_VNS
{
class VNS{
char receive[512];
unsigned char *received;
int vnsSocket;
bool Running;
bool End;
int join_time;
DWORD tid;
HANDLE handle;
public:
struct Acknowledge {
static const unsigned int Ack_ID = 0x82;
unsigned int Error_Type;
unsigned int Reject_Msg_ID;
unsigned int DACK_Msg_ID;
unsigned int DACK_Msg_Counter;
unsigned int DNACK_Msg_ID;
unsigned int DNACK_Msg_Counter;
};
struct Transmit_Rate_DEF_R {
static const unsigned int TR_ID = 0x8A;
unsigned long Validity;
unsigned int TX_Msg_1_ID;
unsigned int TX_Rate_Msg_1;
unsigned int TX_Msg_2_ID;
unsigned int TX_Rate_Msg_2;
unsigned int TX_Msg_3_ID;
unsigned int TX_Rate_Msg_3;
unsigned int TX_Msg_4_ID;
unsigned int TX_Rate_Msg_4;
unsigned int TX_Msg_5_ID;
unsigned int TX_Rate_Msg_5;
};
struct Ether_Confg_Msg_RB_R {
static const unsigned int EC_ID = 0x8C;
unsigned char *MAC_Source;
unsigned char *MAC_Dest;
unsigned char *IP_Source;
unsigned char *IP_Dest;
unsigned int src_port;
unsigned int dest_port;
};
struct System_Parameter_R {
static const unsigned int SP_ID = 0x90;
unsigned long Validity;
unsigned int Map_Datum;
unsigned int heading;
unsigned int altitude;
int utc_TO_hrs;
int utc_TO_mins;
int VMS;
unsigned int mount_pols;
int misalign_Roll;
int misalign_Pitch;
int Angle_Hdg;
unsigned int INU_Mode;
int GPS_X;
int GPS_Y;
int GPS_Z;
unsigned int NMEA_GPS_BR;
unsigned int VMS_Type;
unsigned int GPS_Type_Mode;
unsigned int GSSIP_Init;
unsigned int GSSIP_Mode;
};
struct STD_Output{
static const unsigned int STD_ID = 0x91;
unsigned int Validity_HI;
unsigned int Validity_LO;
unsigned int Update_Counter;
unsigned int Status;
unsigned int Alert;
unsigned int Map_Datum;
unsigned int heading_Format;
unsigned int altitude_Format;
float UTM_Northing;
float UTM_Easting;
unsigned int UTM_Zone;
char *UTM_hemi;
float GEO_Latitude;
float GEO_Longtitude;
float MGRS_Northing;
float MGRS_Easting;
wchar_t MGRS_Row;
wchar_t MGRS_Col;
unsigned int MGRS_Zone;
wchar_t MGRS_Zone_Field;
float Pos_Accuracy;
unsigned int Pos_Src;
float Altitude;
float Alt_Accuracy;
unsigned int Alt_Src;
float heading;
float heading_accuracy;
unsigned int heading_src;
float Pitch;
float Roll;
float Cant;
float roll_pitch_Accuracy;
unsigned int Waypoint_no;
float Waypoint_Dist;
float Waypoint_Bearing;
float Waypoint_Deviation;
float Horizontal_Velocity;
float North_Velocity;
float East_Velocity;
float Down_Velocity;
unsigned int Velocity_Status;
unsigned int Velocity_Source;
float dist_travelled;
unsigned int year;
unsigned int month;
unsigned int Day;
unsigned int Date_status;
unsigned int hours;
unsigned int mins;
unsigned int secs;
unsigned int time_status_src;
unsigned int GPS_DY;
unsigned int GPS_DM;
unsigned int GPS_DD;
unsigned int GPS_UTC_Hours;
unsigned int GPS_UTC_Mins;
unsigned int GPS_UTC_Secs;
float GPS_Latitude;
float GPS_Longtitude;
float GPS_Altitude;
float GPS_track_angle;
float GPS_ground_speed;
float GPS_velocity_north;
float GPS_velocity_east;
float GPS_velocity_up;
float GPS_EHE;
float GPS_EVE;
float GPS_EAE;
float GPS_HDOP;
float GPS_PDOP;
float GPS_VDOP;
unsigned int GPS_NAV_Mode;
unsigned int GPS_Status;
unsigned int VMS_Counter;
unsigned int VMS_Status;
float internal_time;
};
struct Status_BIT
{
static const unsigned int SB_ID = 0x92;
unsigned long Validity;
unsigned char *INU_Part;
unsigned int INU_SN;
unsigned int INU_IDENT;
unsigned int INU_SW;
unsigned int Stat, Alert, Bit1, Bit2, Bit3;
unsigned int LRI_1, LRI_2, LRI_3;
unsigned int Wrap;
};
struct Test_Data
{
static const unsigned int TD_ID = 0x93;
unsigned long Validity;
unsigned int update_counter;
unsigned int vms_counter;
float vms_skf_Deviation;
unsigned int GPS_Stat;
unsigned int viewed_Sate;
unsigned int vms_skf_verification_stat;
unsigned int vms_int_Type2;
};
struct WayPoint_R
{
static const unsigned int WP_ID = 0x94;
unsigned int Waypoint_no;
unsigned char *Waypoint_name;
unsigned int Waypoint_status;
float WP_UTM_Northing;
float WP_UTM_Easting;
unsigned int WP_UTM_Zone;
unsigned char *UTM_Hemi;
float WP_GEO_LT;
float WP_GEO_LONG;
float WP_MGRS_Northing;
float WP_MGRS_Easting;
unsigned char WP_MGRS_RL;
unsigned char WP_MGRS_CL;
unsigned int WP_MGRS_Zone;
unsigned char WP_MGRS_Zone_field;
unsigned int WP_MGRS_Map_datum;
float UTM_Northing;
float UTM_Easting;
unsigned int UTM_Zone;
unsigned char *UTM_Hemisphere;
float GEO_Lat;
float GEO_Long;
float MGRS_Northing;
float MGRS_Easting;
unsigned char MGRS_RL;
unsigned char MGRS_CL;
unsigned int MGRS_Zone;
unsigned char MGRS_Zone_field;
unsigned int heading_Format;
float heading;
float WP_Dist;
float WP_Bearing;
float WP_Deviation;
};
struct Receive {
unsigned int System_Stat;
unsigned int Msg_ID;
unsigned int MsgCounter;
unsigned int LRI_Status;
unsigned long RTI_Count;
unsigned int Version_Num[2];
Acknowledge Ack;
Transmit_Rate_DEF_R trd_R;
Ether_Confg_Msg_RB_R EtherConf_rb_R;
System_Parameter_R SysP_R;
STD_Output StOut;
Status_BIT Bit;
Test_Data td;
WayPoint_R wp_R;
};
struct COMMAND_MESSAGE{
static const unsigned int MCD_ID = 0x86;
unsigned int Req_ID;
unsigned int Command;
float UTM_Northing;
float UTM_Easting;
unsigned int UTM_Zone;
unsigned char UTM_Hemi;
float UTM_Pos;
float Geo_Lat;
float Geo_Long;
float Geo_Pos;
float MGRS_Northing;
float MGRS_Easting;
unsigned char MGRS_ROW;
unsigned char MGRS_COL;
unsigned int MGRS_Zone;
unsigned char MGRS_Field;
float MGRS_PosA;
};
public:
enum Msg_ID
{
SYS_PARAMETER_MSG = 0x90,
STD_OUTPUT_MSG = 0x91,
STATUS_BIT_MSG = 0x92,
TEST_DATA_MSG = 0x93,
WAYPOINT_MSG = 0x94,
};
struct Transmit_Rate_DEF_T{
static const unsigned int TR_ID = 0x8A;
unsigned int TX_Msg1_ID;
unsigned int TX_Rate_Msg1;
unsigned int TX_Msg2_ID;
unsigned int TX_Rate_Msg2;
unsigned int TX_Msg3_ID;
unsigned int TX_Rate_Msg3;
unsigned int TX_Msg4_ID;
unsigned int TX_Rate_Msg4;
unsigned int TX_Msg5_ID;
unsigned int TX_Rate_Msg5;
Msg_ID MSG;
protected:
static const unsigned int MSG_0 = 0;
static const unsigned int MSG_1 = 0.1;
static const unsigned int MSG_2 = 0.25;
static const unsigned int MSG_3 = 0.5;
static const unsigned int MSG_4 = 1.0;
static const unsigned int MSG_5 = 2.0;
static const unsigned int MSG_6 = 4.0;
static const unsigned int MSG_7 = 10.0;
static const unsigned int MSG_8 = 20.0;
static const unsigned int MSG_9 = 40.0;
};
struct Ether_Confg_Msg_RB_T {
static const unsigned int EC_ID = 0x8C;
unsigned char *MAC_Dest;
unsigned char *IP_Source;
unsigned char *IP_Dest;
unsigned int src_port;
unsigned int dest_port;
};
struct System_Parameter_T {
static const unsigned int SP_ID = 0x90;
unsigned int Map_Datum;
unsigned int heading;
unsigned int altitude;
int utc_TO_hrs;
int utc_TO_mins;
int VMS;
unsigned int mount_pols;
int misalign_Roll;
int misalign_Pitch;
int misalign_Angle_Hdg;
unsigned int INU_Mode;
int GPS_X;
int GPS_Y;
int GPS_Z;
unsigned int NMEA_GPS_BR;
unsigned int VMS_Type;
unsigned int GPS_Type_Mode;
unsigned int GSSIP_Init;
unsigned int GSSIP_Mode;
};
struct WayPoint_T
{
static const unsigned int WP_ID = 0x94;
unsigned int Waypoint_no;
unsigned char *Waypoint_name;
unsigned int Waypoint_cmd;
float WP_UTM_Northing;
float WP_UTM_Easting;
unsigned int UTM_Zone;
unsigned char *UTM_Hemi;
float WP_GEO_LT;
float WP_GEO_LONG;
float WP_MGRS_Northing;
float WP_MGRS_Easting;
unsigned char WP_MGRS_RL;
unsigned char WP_MGRS_CL;
unsigned int WP_MGRS_Zone;
unsigned char WP_MGRS_Zone_field;
};
public:
struct Transmit{
static const unsigned int reserved = 0x00;
unsigned int MsgID;
unsigned int msg_count;
unsigned int validity;
COMMAND_MESSAGE comd_Msg;
Transmit_Rate_DEF_T trd_T;
Ether_Confg_Msg_RB_T EtherConfg_rbT;
System_Parameter_T SysP_T;
WayPoint_T WP_T;
};
public:
VNS(unsigned int port);
static int initSock( unsigned int port );
static int endSock( int sock );
static int rec( int sock, char * buffer, int len,char * senderipaddress );
static int send( int sock, const char * data, int len, const char * targetIpAdr, int port );
static DWORD WINAPI ReceiveThread(void *param);
void InitiateThread();
DWORD ThreadRun();
void decode_Message(unsigned char *data);
void Standard_Output(unsigned char *data);
public:
Receive Recv;
Transmit Trans;
};
}
#endif
.cpp file :
#include <cstdio>
#include "VNS_Lib.h"
#include <iostream>
using namespace std;
using namespace WAVE_VNS;
VNS::VNS(unsigned int port)
{
vnsSocket = initSock(port);
received = new unsigned char[512];
Running = false;
End = false;
join_time = 100;
tid = 0;
handle = 0;
}
DWORD WINAPI VNS::ReceiveThread(void *param)
{
VNS *func = static_cast<VNS*>(param);
return func->ThreadRun();
}
DWORD VNS::ThreadRun()
{
Running = true;
do
{
printf("Thread Running %d\n", tid);
decode_Message(received);
Sleep(1000); }while (!End);
Running = false;
return 0;
}
void VNS::decode_Message(unsigned char *data)
{
switch(data[1])
{
case 0x91:
Standard_Output(data);
break;
}
}
void VNS::Standard_Output(unsigned char *data)
{
Recv.System_Stat = data[0];
unsigned int Zone_Change_request = data[0] & 0x80;
unsigned int Pos_Update_request = data[0] & 0x40;
unsigned int Update_Mode_Active = data[0] & 0x20;
unsigned int Command_Rejected = data[0] & 0x10;
unsigned int Mode_indicator_1 = data[0] & 0x08;
unsigned int Mode_indicator_2 = data[0] & 0x04;
unsigned int Mode_indicator_3 = data[0] & 0x02;
unsigned int Mode_indicator_4 = data[0] && 0x01;
if (Zone_Change_request == 0x80)
{
printf("\nZone Change Request activated");
}
else
printf("\nZone Change Request NOT activated");
if (Pos_Update_request == 0x40)
{
printf("\nPost Update Request activated");
}
else
printf("\nPost Update Request NOT activated");
if (Update_Mode_Active == 0x20)
{
printf("\nUpdate Mode Active activated");
}
else
printf("\nUpdate Mode Active Not activated");
if (Command_Rejected == 0x10)
{
printf("\nCommand Rejected");
}
else
printf("\nCommand Not Rejected");
if ((Mode_indicator_1 == 0x00) && (Mode_indicator_2 == 0x00) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x00))
{
printf("\nPOWER ON");
}
else if ((Mode_indicator_1 == 0x00) && (Mode_indicator_2 == 0x04) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x00))
{
printf("\nNAV Motion");
}
else if ((Mode_indicator_1 == 0x00) && (Mode_indicator_2 == 0x04) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x01))
{
printf("\nNAV Standstill");
}
else if ((Mode_indicator_1 == 0x00) && (Mode_indicator_2 == 0x04) && (Mode_indicator_3 == 0x02) && (Mode_indicator_4 == 0x01))
{
printf("\nAmphibious Mode");
}
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x00) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x00))
{
printf("\nTest");
}
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x00) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x01))
{
printf("\nFault");
}
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x00) && (Mode_indicator_3 == 0x02) && (Mode_indicator_4 == 0x00))
{
printf("\nLoader Active");
}
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x00) && (Mode_indicator_3 == 0x02) && (Mode_indicator_4 == 0x01))
{
printf("\nFault: GPS Backup");
}
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x04) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x00))
{
printf("\nAUTONAV Motion");
}
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x04) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x01))
{
printf("\nAUTONAV Standstill");
}
else
{
printf("\nNot Valid");
}
unsigned int Fault = data[4] & 0x80;
unsigned int INU_Fail = data[4] & 0x40;
unsigned int GPS_Fail = data[4] & 0x20;
unsigned int VMS_Fail = data[4] & 0x10;
unsigned int GSP_Type = data[4] & 0x08;
unsigned int GPS_Ant = data[4] & 0x04;
unsigned int GPS_Pwr = data[4] & 0x02;
unsigned int GPS_Data = data[4] & 0x01;
Recv.LRI_Status = data[4];
if (Fault == 0x80)
{
printf("\nFault");
}
else
printf("\nFault Not true");
if (INU_Fail == 0x40)
{
printf("\nINU Fail");
}
else
printf("\nINU OK");
if (GPS_Fail == 0x20)
{
printf("\nGPS Fail");
}
else
printf("\nGPS OK");
if (VMS_Fail == 0x10)
{
printf("\nVMS Fail");
}
else
printf("\nVMS OK");
if (GSP_Type == 0x08)
{
printf("\nGPS Type: C/A");
}
else
printf("\nGPS Type: P(Y)");
if (GPS_Ant == 0x04)
{
printf("\nGPS ANT: Int");
}
else
printf("\nGPS ANT: Ext");
if (GPS_Pwr == 0x02)
{
printf("\nGPS Pwr: Int");
}
else
printf("\nGPS Pwr: Ext");
if (GPS_Data == 0x01)
{
printf("\nGPS Data: Used");
}
else
printf("\nGPS Data: Not Used");
int datum = data[28];
Recv.StOut.Map_Datum = data[28];
Recv.StOut.heading_Format = data[29];
if (data[29] == 0x00)
{
printf("\nGeodetic");
}
else
printf("\nGrid");
Recv.StOut.altitude_Format = data[30];
if (data[30] == 0x00)
{
printf("\nMSL");
}
else
printf("\nDatum");
unsigned char Northing[8];
Northing[0] = data[38];
Northing[1] = data[37];
Northing[2] = data[36];
Northing[3] = data[35];
Northing[4] = data[34];
Northing[5] = data[33];
Northing[6] = data[32];
Northing[7] = data[31];
memcpy(&Recv.StOut.UTM_Northing, Northing, 8);
unsigned char Easting[8];
Easting[0] = data[46];
Easting[1] = data[45];
Easting[2] = data[44];
Easting[3] = data[43];
Easting[4] = data[42];
Easting[5] = data[41];
Easting[6] = data[40];
Easting[7] = data[39];
memcpy(&Recv.StOut.UTM_Easting, Easting, 8);
int Zone = data[47];
Recv.StOut.UTM_Zone = Zone;
unsigned char hemi = data[48];
if (hemi == 0x4E)
printf("\nNorth");
else if (hemi == 0x53)
printf("\nSouth");
else
printf("\n-");
unsigned char Alt[8];
Alt[0] = data[97];
Alt[1] = data[96];
Alt[2] = data[95];
Alt[3] = data[94];
Alt[4] = data[93];
Alt[5] = data[92];
Alt[6] = data[91];
Alt[7] = data[90];
memcpy(&Recv.StOut.Altitude, Alt, 8);
unsigned char head[8];
head[0] = data[110];
head[1] = data[109];
head[2] = data[108];
head[3] = data[107];
head[4] = data[106];
head[5] = data[105];
head[6] = data[104];
head[7] = data[103];
memcpy(&Recv.StOut.heading, head, 8);
unsigned char pitch[8];
pitch[0] = data[123];
pitch[1] = data[122];
pitch[2] = data[121];
pitch[3] = data[120];
pitch[4] = data[119];
pitch[5] = data[118];
pitch[6] = data[117];
pitch[7] = data[116];
memcpy(&Recv.StOut.Pitch, pitch, 8);
unsigned char Rl[8];
Rl[0] = data[131];
Rl[1] = data[130];
Rl[2] = data[129];
Rl[3] = data[128];
Rl[4] = data[127];
Rl[5] = data[126];
Rl[6] = data[125];
Rl[7] = data[124];
memcpy(&Recv.StOut.Roll, Rl, 8);
unsigned char Ct[8];
Ct[0] = data[139];
Ct[1] = data[138];
Ct[2] = data[137];
Ct[3] = data[136];
Ct[4] = data[135];
Ct[5] = data[134];
Ct[6] = data[133];
Ct[7] = data[132];
memcpy(&Recv.StOut.Cant, Ct, 8);
unsigned char ac[4];
ac[0] = data[143];
ac[1] = data[142];
ac[2] = data[141];
ac[3] = data[140];
memcpy(&Recv.StOut.roll_pitch_Accuracy, ac, 4);
unsigned char dis[4];
dis[0] = data[196];
dis[1] = data[195];
dis[2] = data[194];
dis[3] = data[193];
memcpy(&Recv.StOut.dist_travelled, dis, 4);
unsigned char yr[2];
yr[0] = data[198];
yr[1] = data[197];
memcpy(&Recv.StOut.year, yr, 2);
int month = data[199];
Recv.StOut.month = month;
int day = data[200];
Recv.StOut.Day = day;
unsigned int Stat = data[201] & 0x01;
Recv.StOut.Date_status = data[201];
if (Stat == 0x01)
{
printf("\nGPS Date");
}
else
printf("\nInternal Date");
int hour = data[202];
Recv.StOut.hours = hour;
int min = data[203];
Recv.StOut.mins = min;
float secs = data[204];
Recv.StOut.secs = secs;
unsigned int down = data[191] & 0x08;
unsigned int E = data[191] & 0x04;
unsigned int N = data[191] & 0x02;
unsigned int horz = data[191] & 0x01;
Recv.StOut.Velocity_Status = data[191];
if (horz == 0x01)
{
printf("\nHorizontal");
}
if (N == 0x02)
{
printf("\nNorth");
}
if (E == 0x04)
{
printf("\nEast");
}
if (down == 0x08)
{
printf("\nDown");
}
unsigned int vs02 = data[192] & 0x02;
unsigned int vs01 = data[192] & 0x01;
Recv.StOut.Velocity_Source = data[192];
if ((vs02 == 0x02) && (vs01 == 0x01))
{
printf("\nINS (Hybrid)");
}
else if ((vs02 == 0x02) && (vs01 == 0x00))
{
printf("\nGPS");
}
else if ((vs02 == 0x00) && (vs01 == 0x01))
{
printf("\nVMS");
}
else
{
printf("\nNot Available");
}
unsigned char Glat[8];
Glat[0] = data[56];
Glat[1] = data[55];
Glat[2] = data[54];
Glat[3] = data[53];
Glat[4] = data[52];
Glat[5] = data[51];
Glat[6] = data[50];
Glat[7] = data[49];
memcpy(&Recv.StOut.GEO_Latitude, Glat, 8);
unsigned char Glong[8];
Glong[0] = data[64];
Glong[1] = data[63];
Glong[2] = data[62];
Glong[3] = data[61];
Glong[4] = data[60];
Glong[5] = data[59];
Glong[6] = data[58];
Glong[7] = data[57];
memcpy(&Recv.StOut.GEO_Longtitude, Glong, 8);
unsigned char MNorth[8];
MNorth[0] = data[72];
MNorth[1] = data[71];
MNorth[2] = data[70];
MNorth[3] = data[69];
MNorth[4] = data[68];
MNorth[5] = data[67];
MNorth[6] = data[66];
MNorth[7] = data[65];
memcpy(&Recv.StOut.MGRS_Northing, MNorth, 8);
unsigned char MEast[8];
MEast[0] = data[80];
MEast[1] = data[79];
MEast[2] = data[78];
MEast[3] = data[77];
MEast[4] = data[76];
MEast[5] = data[75];
MEast[6] = data[74];
MEast[7] = data[73];
memcpy(&Recv.StOut.MGRS_Easting, MEast, 8);
wchar_t Row = data[81];
Recv.StOut.MGRS_Row = Row;
wchar_t Col = data[82];
Recv.StOut.MGRS_Col = Col;
int MZ = data[83];
Recv.StOut.MGRS_Zone = MZ;
wchar_t Field = data[84];
Recv.StOut.MGRS_Zone_Field =Field;
}
void VNS::InitiateThread()
{
handle = CreateThread(NULL,0,ReceiveThread,(void *)this,0,&tid);
}
int VNS::initSock( unsigned int port )
{
SOCKADDR_IN sin;
int sock ;
unsigned long io ;
int ret ;
ret = 0 ;
io = 1 ;
WSAData data;
WSAStartup( MAKEWORD( 2, 2 ), &data );
if( port < 0 || port > 65535 ) return -9;
sin.sin_family=AF_INET;
sin.sin_addr.s_addr=INADDR_ANY; sin.sin_port=htons( (unsigned short)port);
if ( ( sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) < 0 )
{
fprintf( stderr, "init : socket sock=%d error=%d \n",sock,LOC_ERRNO );
ret = -1 ;
}
else if( bind( sock, (const SOCKADDR *)( &sin ), sizeof( sin ) ) != 0 )
{
fprintf( stderr, "init : bind error %d\n", LOC_ERRNO );
ret = -1 ;
}
else
{
if ( ioctlsocket( sock, FIONBIO, &io ) < 0 )
{
fprintf( stderr, " init : ioctl error %d\n", LOC_ERRNO );
ret = -1 ;
}
else
{
return sock ;
}
}
return ret ;
}
int VNS::endSock( int sock )
{
int ret;
ret = 0;
if ( closesocket(sock) != 0 )
{
fprintf( stderr, "endSock close errno=%d \n",LOC_ERRNO );
ret = -1;
}
WSACleanup();
return ret;
}
int VNS::rec( int sock, char * buffer, int len, char * senderipaddress )
{
SOCKADDR_IN sin;
int ret, mok, sinsize = sizeof( sin );
mok = 0 ;
ret = recvfrom( sock , buffer, len, 0, ( SOCKADDR *)&sin, &sinsize );
if ( ret == -1 )
{
if ( LOC_ERRNO == WSAEWOULDBLOCK )
{ ret = 0 ;
}
else
{ fprintf( stderr, " recvfrom error errno=%d\n", LOC_ERRNO );
ret = -2 ;
}
}
else
{
senderipaddress = inet_ntoa( sin.sin_addr );
ret = 1;
}
return ret;
}
int VNS::send( int sock, const char * data, int len, const char * targetIpAdr, int port )
{
int Messlen, ret;
SOCKADDR_IN peerAdr;
Messlen = len ;
peerAdr.sin_family = AF_INET;
peerAdr.sin_addr.s_addr = inet_addr( targetIpAdr ); peerAdr.sin_port = htons( ( unsigned short )port );
if ( sock <= 0 ) return -7 ;
if ( ( ret = sendto( sock, data, len, 0, ( const SOCKADDR *)&peerAdr, sizeof( SOCKADDR ) ) )
!= Messlen )
{
if( ret == -1 && LOC_ERRNO == WSAEWOULDBLOCK ) return -1;
if( ret == -1 && LOC_ERRNO == WSAEHOSTDOWN ) return -9;
fprintf( stderr, "sendTo error errno=%d ret=%d \n", LOC_ERRNO, ret );
return -4;
}
else
{
return 0;
}
}
the console .cpp file:
#include "stdafx.h"
#include "VNS_Output.h"
VNS_Output::VNS_Output()
{
VNS *v1 = new VNS(EDIP_UDP_PORT_NO);
}
following is the encountered errors:
error LNK2019: unresolved external symbol "public: __thiscall WAVE_VNS::VNS::VNS(unsigned int)" (??0VNS@WAVE_VNS@@QAE@I@Z) referenced in function "public: __thiscall VNS_Output::VNS_Output(void)" (??0VNS_Output@@QAE@XZ)
error LNK2005: "bool threadFinished" (?threadFinished@@3_NA) already defined in VNS_Console.obj
I'm not really sure how to solve the problem. Any suggestions will be greatly appreciated. thanks! :)