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. UCHAR to CString

UCHAR to CString

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
5 Posts 5 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.
  • P Offline
    P Offline
    packetlos
    wrote on last edited by
    #1

    Hi i wonder if anybody can answer this (simple?) question, i have a buffer returned from a library call declared as: const UCHAR* pkt_data and i want to fill a CString object from a certain postion from that buffer, say 14 charachers in, I have looked at all the CString articles here and for the life of me cannot figure out how to do it. Can anybody be so kind as to post a code snippet? Cheers Andy

    R J D J 4 Replies Last reply
    0
    • P packetlos

      Hi i wonder if anybody can answer this (simple?) question, i have a buffer returned from a library call declared as: const UCHAR* pkt_data and i want to fill a CString object from a certain postion from that buffer, say 14 charachers in, I have looked at all the CString articles here and for the life of me cannot figure out how to do it. Can anybody be so kind as to post a code snippet? Cheers Andy

      J Offline
      J Offline
      jmkhael
      wrote on last edited by
      #2

      CString str; int iOffset=2; str = _T(pkt_data+iOffset); Papa while (TRUE) Papa.WillLove ( Bebe ) ;

      1 Reply Last reply
      0
      • P packetlos

        Hi i wonder if anybody can answer this (simple?) question, i have a buffer returned from a library call declared as: const UCHAR* pkt_data and i want to fill a CString object from a certain postion from that buffer, say 14 charachers in, I have looked at all the CString articles here and for the life of me cannot figure out how to do it. Can anybody be so kind as to post a code snippet? Cheers Andy

        R Offline
        R Offline
        Rory Solley
        wrote on last edited by
        #3

        I'm assuming the data returned is standard text, you can do something like: CString strMyString = reinterpret_cast(&pkt_data[14]);

        1 Reply Last reply
        0
        • P packetlos

          Hi i wonder if anybody can answer this (simple?) question, i have a buffer returned from a library call declared as: const UCHAR* pkt_data and i want to fill a CString object from a certain postion from that buffer, say 14 charachers in, I have looked at all the CString articles here and for the life of me cannot figure out how to do it. Can anybody be so kind as to post a code snippet? Cheers Andy

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          How about:

          CString str;
          strcpy(str.GetBuffer(###), ...);
          str.ReleaseBuffer();

          You might also be able to use CString's assignment operator, but I've not tried it so I can't say for sure.


          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

          1 Reply Last reply
          0
          • P packetlos

            Hi i wonder if anybody can answer this (simple?) question, i have a buffer returned from a library call declared as: const UCHAR* pkt_data and i want to fill a CString object from a certain postion from that buffer, say 14 charachers in, I have looked at all the CString articles here and for the life of me cannot figure out how to do it. Can anybody be so kind as to post a code snippet? Cheers Andy

            J Offline
            J Offline
            John R Shaw
            wrote on last edited by
            #5

            The type UCHAR* and the name pkt_data sugest this is probubly a pointer to binary data, in which case you should be using a CByteArray. If you know the data you wish to copy has no bytes equal to zero and you still want to copy it to a CString then the sipilest way is as follows:

            // assumes non-UNICODE version of program
            CString str;
            for( int i=0; i<14; ++i )
            {
            str += (char)pkt_data[i];
            }

            INTP

            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