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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Easy question, but im stuck. :)

Easy question, but im stuck. :)

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

    How do I get the contents of CString m_strData into BYTE* m_pData? I have a edit box that has a member variable of m_strData, and I need to get the string into the m_pData variable. Thanks :)

    S G 2 Replies Last reply
    0
    • A Anonymous

      How do I get the contents of CString m_strData into BYTE* m_pData? I have a edit box that has a member variable of m_strData, and I need to get the string into the m_pData variable. Thanks :)

      S Offline
      S Offline
      Schnemar
      wrote on last edited by
      #2

      try this one: CString strTemp = "Hello World"; BYTE* pByte = (BYTE*) (LPCTSTR) strTemp; MS

      D 1 Reply Last reply
      0
      • A Anonymous

        How do I get the contents of CString m_strData into BYTE* m_pData? I have a edit box that has a member variable of m_strData, and I need to get the string into the m_pData variable. Thanks :)

        G Offline
        G Offline
        Gary Kirkham
        wrote on last edited by
        #3

        What Martin suggested sets m_pData to point to m_strData. I interpret your question as...You want to copy the contents of m_strData to m_pData(which is already allocated). If so you could use memcpy or strcpy and cast m_pData to a char* Gary Kirkham A working Program is one that has only unobserved bugs

        A 1 Reply Last reply
        0
        • S Schnemar

          try this one: CString strTemp = "Hello World"; BYTE* pByte = (BYTE*) (LPCTSTR) strTemp; MS

          D Offline
          D Offline
          Daniel Turini
          wrote on last edited by
          #4

          NO!!! This is dangerous! You need to do this: CString strTemp = "Hello World"; BYTE* pByte = (BYTE*) strTemp.LockBuffer(); and when pByte is not needed anymore: strTemp.UnlockBuffer(); Never cast away the const-ness of a pointer... Concussus surgo. When struck I rise.

          1 Reply Last reply
          0
          • G Gary Kirkham

            What Martin suggested sets m_pData to point to m_strData. I interpret your question as...You want to copy the contents of m_strData to m_pData(which is already allocated). If so you could use memcpy or strcpy and cast m_pData to a char* Gary Kirkham A working Program is one that has only unobserved bugs

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Yes I wanted to copy the string thats held in m_strData into m_pData.. I used his suggestion and it worked fine.. I just saw the second post and will adjust my code... Thanks everyone!

            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