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. Conversion

Conversion

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
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.
  • R Offline
    R Offline
    reddy07
    wrote on last edited by
    #1

    Hi I am devloping an application in MFC I need to convert UCAHR pointer to Cstring and vice versa such as UCHAR *pMsg; pMsg[0] = '1'; pMsg[1] = '2'; pMsg[3] = '3'; pMsg[4] = NULL to CString and viceversa... Can anybody help.

    C CPalliniC R 3 Replies Last reply
    0
    • R reddy07

      Hi I am devloping an application in MFC I need to convert UCAHR pointer to Cstring and vice versa such as UCHAR *pMsg; pMsg[0] = '1'; pMsg[1] = '2'; pMsg[3] = '3'; pMsg[4] = NULL to CString and viceversa... Can anybody help.

      C Offline
      C Offline
      Crazy Wu
      wrote on last edited by
      #2

      uchar * to cstring? CString ps; UCHAR *pMsg=new UCHAR[4]; pMsg[0] = '1'; pMsg[1] = '2'; pMsg[2] = '3'; pMsg[3] = '\0'; ps=CString(pMsg);

      1 Reply Last reply
      0
      • R reddy07

        Hi I am devloping an application in MFC I need to convert UCAHR pointer to Cstring and vice versa such as UCHAR *pMsg; pMsg[0] = '1'; pMsg[1] = '2'; pMsg[3] = '3'; pMsg[4] = NULL to CString and viceversa... Can anybody help.

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        reddy07 wrote:

        UCHAR *pMsg; pMsg[0] = '1'; pMsg[1] = '2'; pMsg[3] = '3'; pMsg[4] = NULL

        As it stands, there is a access violation on your horizon. Anyway the CString constructor is probably able to handle your unsigned char array, for instance try

        CString s((char*) pMsg);

        On the other hand, if you need to convert the CString value to an array of unsigned chars, then the effort required may depend on the type of build you are doing, UNICODE or not. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • R reddy07

          Hi I am devloping an application in MFC I need to convert UCAHR pointer to Cstring and vice versa such as UCHAR *pMsg; pMsg[0] = '1'; pMsg[1] = '2'; pMsg[3] = '3'; pMsg[4] = NULL to CString and viceversa... Can anybody help.

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          Hello! If you wanted a deeper understanding of the topic, I'll recommend you this article: CString Management[^].

          It is a crappy thing, but it's life -^ Carlo Pallini

          R 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            Hello! If you wanted a deeper understanding of the topic, I'll recommend you this article: CString Management[^].

            It is a crappy thing, but it's life -^ Carlo Pallini

            R Offline
            R Offline
            reddy07
            wrote on last edited by
            #5

            Thank you guys, it was very helpful.

            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