VC++ - AciveXDLL -Sockets
-
Hi EveryOne, In ActivexDLL I have written a method called Connect(..)inside a class. The method exposes the functionality of connecting to another system using sockets. The problem here is when I compile my project I am getting link errors(unresolved external symbol). These errors are thrown when winsocks methods are called like htos(),inet_addr(),connect() are called. Unresolved symbol (upto my knowledge) are thrown when the function definition is unknown or its different from the one that is implemented. since I am using an inbuild function (used the header file winsock2.h) what might be the cause to the problem? How would I Overcome it. Please find the code below.
STDMETHODIMP CRAPClientX::Connect(BSTR serverIP, BSTR serverPort,BSTR *output) { // TODO: Add your implementation code here /**output=SysAllocString(L"Connected"); return S_OK;*/ //---------------------- // Initialize Winsock WSADATA wsaData; char returnString[150]; int iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != NO_ERROR) printf("Error at WSAStartup()\n"); //---------------------- // Create a SOCKET for connecting to server SOCKET ConnectSocket; ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (ConnectSocket == INVALID_SOCKET) { sprintf(returnString,"Error at socket(): %ld\n", WSAGetLastError()); *output=SysAllocString(_bstr_t(returnString)); WSACleanup(); return S_OK; } //---------------------- // The sockaddr_in structure specifies the address family, // IP address, and port of the server to be connected to. sockaddr_in clientService; clientService.sin_family = AF_INET; clientService.sin_addr.s_addr = **inet_addr("127.0.0.1" )**; clientService.sin_port = **htons( 27015 )**; //---------------------- // Connect to server. if ( **connect(ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR)** { sprintf( returnString,"Failed to connect.\n" ); *output=SysAllocString(_bstr_t(returnString)); WSACleanup(); return S_OK; } sprintf(returnString,"Connected to server.\n"); *output=SysAllocString(_bstr_t(returnString)); WSACleanup(); return S_OK; }
kinldy reply. Regards, LG.:confused:lgatcodeproject
-
Hi EveryOne, In ActivexDLL I have written a method called Connect(..)inside a class. The method exposes the functionality of connecting to another system using sockets. The problem here is when I compile my project I am getting link errors(unresolved external symbol). These errors are thrown when winsocks methods are called like htos(),inet_addr(),connect() are called. Unresolved symbol (upto my knowledge) are thrown when the function definition is unknown or its different from the one that is implemented. since I am using an inbuild function (used the header file winsock2.h) what might be the cause to the problem? How would I Overcome it. Please find the code below.
STDMETHODIMP CRAPClientX::Connect(BSTR serverIP, BSTR serverPort,BSTR *output) { // TODO: Add your implementation code here /**output=SysAllocString(L"Connected"); return S_OK;*/ //---------------------- // Initialize Winsock WSADATA wsaData; char returnString[150]; int iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != NO_ERROR) printf("Error at WSAStartup()\n"); //---------------------- // Create a SOCKET for connecting to server SOCKET ConnectSocket; ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (ConnectSocket == INVALID_SOCKET) { sprintf(returnString,"Error at socket(): %ld\n", WSAGetLastError()); *output=SysAllocString(_bstr_t(returnString)); WSACleanup(); return S_OK; } //---------------------- // The sockaddr_in structure specifies the address family, // IP address, and port of the server to be connected to. sockaddr_in clientService; clientService.sin_family = AF_INET; clientService.sin_addr.s_addr = **inet_addr("127.0.0.1" )**; clientService.sin_port = **htons( 27015 )**; //---------------------- // Connect to server. if ( **connect(ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR)** { sprintf( returnString,"Failed to connect.\n" ); *output=SysAllocString(_bstr_t(returnString)); WSACleanup(); return S_OK; } sprintf(returnString,"Connected to server.\n"); *output=SysAllocString(_bstr_t(returnString)); WSACleanup(); return S_OK; }
kinldy reply. Regards, LG.:confused:lgatcodeproject
lgatcodeproject wrote:
Unresolved symbol (upto my knowledge) are thrown when the function definition is unknown or its different from the one that is implemented. since I am using an inbuild function (used the header file winsock2.h) what might be the cause to the problem?
Not linking to the lib file in which these functions are defined might be one cause :) . So, did you link your project to ws2_32.lib ?
Cédric Moonen Software developer
Charting control [v1.4] -
lgatcodeproject wrote:
Unresolved symbol (upto my knowledge) are thrown when the function definition is unknown or its different from the one that is implemented. since I am using an inbuild function (used the header file winsock2.h) what might be the cause to the problem?
Not linking to the lib file in which these functions are defined might be one cause :) . So, did you link your project to ws2_32.lib ?
Cédric Moonen Software developer
Charting control [v1.4]Cedric Once I posted this question, I got the question which u asked; in my mind and then included the library (which I missed out earlier :( )WS2_32.LIB. So I fixed it in the time you answered the question. sorry for wasting your time Cedric and thanks for the reply. Regards, LG. :)
lgatcodeproject
-
lgatcodeproject wrote:
Unresolved symbol (upto my knowledge) are thrown when the function definition is unknown or its different from the one that is implemented. since I am using an inbuild function (used the header file winsock2.h) what might be the cause to the problem?
Not linking to the lib file in which these functions are defined might be one cause :) . So, did you link your project to ws2_32.lib ?
Cédric Moonen Software developer
Charting control [v1.4]hmmf. :omg: Got exhausted while recalling the library name for sockets :laugh:
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
hmmf. :omg: Got exhausted while recalling the library name for sockets :laugh:
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
:-D In fact, I had to open a project in which I'm using sockets to recall the name ;P
Cédric Moonen Software developer
Charting control [v1.4] -
:-D In fact, I had to open a project in which I'm using sockets to recall the name ;P
Cédric Moonen Software developer
Charting control [v1.4]So guess its toooo much of Memory Recall hapenning today hmmm :) Regards, LG.
lgatcodeproject