Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. VC++ - AciveXDLL -Sockets

VC++ - AciveXDLL -Sockets

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++sysadminquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lgatcodeproject
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • L 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

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      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]

      L _ 2 Replies Last reply
      0
      • C Cedric Moonen

        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]

        L Offline
        L Offline
        lgatcodeproject
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • C Cedric Moonen

          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]

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #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_

          C 1 Reply Last reply
          0
          • _ _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_

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            :-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]

            L 1 Reply Last reply
            0
            • C Cedric Moonen

              :-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]

              L Offline
              L Offline
              lgatcodeproject
              wrote on last edited by
              #6

              So guess its toooo much of Memory Recall hapenning today hmmm :) Regards, LG.

              lgatcodeproject

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups