c++ - Establishing a tcp connection from within a DLL -
i'm trying write piece of code allow me establish tcp connection within dll file. here's situation: have ruby application needs able send , receive data on socket, can not access native ruby socket methods because of environment in running. can access dll file , run functions within that, figured create wrapper winsock. unfortunately, attempting take piece of code should connect tcp socket in normal c++ application throws slew of lnk2019 errors can not life of me resolve.
this method i'm using connect:
//socket variable socket s; //establishes connection server int server_connect(char* addr, int port) { //start winsock wsadata wsadata; int error = wsastartup(0x0202, &wsadata); //check if happened if (error) return -1; //verify winock version if (wsadata.wversion != 0x0202) { //clean , close wsacleanup(); return -2; } //get information needed finalize socket sockaddr_in target; target.sin_family = af_inet; //address family internet target.sin_port = _winsockapi_::htons(port); //port # target.sin_addr.s_addr = inet_addr(addr); //create socket s = socket(af_inet, sock_stream, ipproto_tcp); if (s == invalid_socket) { return -3; } //try connecting if (connect(s, (sockaddr *)&target, sizeof(target)) == socket_error) { //failed connect return -4; } else { //success return 1; } }
the exact errors i'm receiving are:
error 1 error lnk2019: unresolved external symbol _closesocket@4 referenced in function _server_disconnect [project path] error 2 error lnk2019: unresolved external symbol _connect@12 referenced in function _server_connect [project path] error 3 error lnk2019: unresolved external symbol _htons@4 referenced in function _server_connect [project path] error 4 error lnk2019: unresolved external symbol _inet_addr@4 referenced in function _server_connect [project path] error 5 error lnk2019: unresolved external symbol _socket@12 referenced in function _server_connect [project path] error 6 error lnk2019: unresolved external symbol _wsastartup@8 referenced in function _server_connect [project path] error 7 error lnk2019: unresolved external symbol _wsacleanup@0 referenced in function _server_connect [project path] error 8 error lnk1120: 7 unresolved externals [project path] 1 1
many thanks!
this expected. link project ws2_32.lib
on modern windows systems. executable pick dll same name.
Comments
Post a Comment