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. Socket programming

Socket programming

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 2 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.
  • V Offline
    V Offline
    vinsankar
    wrote on last edited by
    #1

    I had created a structure with six members of type CString. I am trying to send this structure using the 'Send' command. A Pointer object is created for the structure. At the receiving end i had created the same structure. But when i was trying to display the data , I got only a blank message box. Can anyone solve this problem? source prg .......... Struct message { CString name; ... }; message *obj=new message(); Send(obj,sizeof(struct message)); dest prog ........ Struct message { CString name; ... }; message *obj=new message(); Receive(obj,sizeof(struct message)); MessageBox(obj->name); //blank message box was displayed ? vinsankar

    G 1 Reply Last reply
    0
    • V vinsankar

      I had created a structure with six members of type CString. I am trying to send this structure using the 'Send' command. A Pointer object is created for the structure. At the receiving end i had created the same structure. But when i was trying to display the data , I got only a blank message box. Can anyone solve this problem? source prg .......... Struct message { CString name; ... }; message *obj=new message(); Send(obj,sizeof(struct message)); dest prog ........ Struct message { CString name; ... }; message *obj=new message(); Receive(obj,sizeof(struct message)); MessageBox(obj->name); //blank message box was displayed ? vinsankar

      G Offline
      G Offline
      greba
      wrote on last edited by
      #2

      The problem with your code is that sizeof(struct message) is going to return the same number no matter what the size of the string. That is because the CString class has a pointer to a buffer which contains the actual string. You have just stumbled upon a problem that occurs very often. There are many ways around this, but the simpliest one I can think of would be to change your struct to: struct message { char name[256]; }; sizeof(struct message) would then return 256. This method is inefficient, as the whole buffer would be transferred, and it would be tougher to work with the char arrays instead of the CString's. Greba, My lack of content on my home page should be entertaining.

      V 1 Reply Last reply
      0
      • G greba

        The problem with your code is that sizeof(struct message) is going to return the same number no matter what the size of the string. That is because the CString class has a pointer to a buffer which contains the actual string. You have just stumbled upon a problem that occurs very often. There are many ways around this, but the simpliest one I can think of would be to change your struct to: struct message { char name[256]; }; sizeof(struct message) would then return 256. This method is inefficient, as the whole buffer would be transferred, and it would be tougher to work with the char arrays instead of the CString's. Greba, My lack of content on my home page should be entertaining.

        V Offline
        V Offline
        vinsankar
        wrote on last edited by
        #3

        why can't we use CString instead of character arrays ? I am in need of CString values at the receving end.Because I have to perform some trimming operations at the receiving side. What is the real problem while displaying the values stored in structure? Is there any other way to send a structure through the 'Send' command? vinsankar

        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