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. convert cstring to LPBYTE

convert cstring to LPBYTE

Scheduled Pinned Locked Moved C / C++ / MFC
json
11 Posts 6 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 amit code

    I want to convert a cstring into LPBYTE but each time i convert it only first character get stored in the LPBYTE and rest of the string is truncated. Thanks

    amit

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

    First important point: why do you want to do such a thing ? Are you aware about unicode/non-unicode ? If not, I highly suggest reading this article[^] before going further. Post also your code to see what you are doing wrong.

    Cédric Moonen Software developer
    Charting control [v1.5] OpenGL game tutorial in C++

    A 1 Reply Last reply
    0
    • A amit code

      I want to convert a cstring into LPBYTE but each time i convert it only first character get stored in the LPBYTE and rest of the string is truncated. Thanks

      amit

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

      amit.code wrote:

      I want to convert a cstring into LPBYTE...

      How are you doing it? Something like:

      CString name("Name");
      const LPBYTE lp = (const LPBYTE) (LPCSTR) name;

      amit.code wrote:

      ...but each time i convert it only first character get stored in the LPBYTE and rest of the string is truncated.

      How are you verifying this? Is Unicode defined?

      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      A 1 Reply Last reply
      0
      • C Cedric Moonen

        First important point: why do you want to do such a thing ? Are you aware about unicode/non-unicode ? If not, I highly suggest reading this article[^] before going further. Post also your code to see what you are doing wrong.

        Cédric Moonen Software developer
        Charting control [v1.5] OpenGL game tutorial in C++

        A Offline
        A Offline
        amit code
        wrote on last edited by
        #4

        Hi .. thanks for prompt reply. I am getting a file in cstring and i want to parse. The parser take the data in LPBYTE format and file data contain few words in languge other than english thats why i am taking cstring to store it. But when i convert cstring to lpbyte only first character get stores. Meanwhile i am going through the link you have sent.

        amit

        1 Reply Last reply
        0
        • D David Crow

          amit.code wrote:

          I want to convert a cstring into LPBYTE...

          How are you doing it? Something like:

          CString name("Name");
          const LPBYTE lp = (const LPBYTE) (LPCSTR) name;

          amit.code wrote:

          ...but each time i convert it only first character get stored in the LPBYTE and rest of the string is truncated.

          How are you verifying this? Is Unicode defined?

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          A Offline
          A Offline
          amit code
          wrote on last edited by
          #5

          Yes .. i have also tried the method that you mentioned. I am parsing that whole data that comes in lpbyte but it shows only one character. During debugging I am verifying it also throughg watch window. Thanks

          amit

          1 Reply Last reply
          0
          • A amit code

            I want to convert a cstring into LPBYTE but each time i convert it only first character get stored in the LPBYTE and rest of the string is truncated. Thanks

            amit

            C Offline
            C Offline
            Code o mat
            wrote on last edited by
            #6

            Could it be that you are feeding a unicode string to something that expects a simple ASCII string? Also note, that LPBYTE is porbably not recognized as a string by the debugger, thus it will only show you the pointer's value (the address it is pointing at) and maybe the one byte it is pointing at.

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

            A 1 Reply Last reply
            0
            • C Code o mat

              Could it be that you are feeding a unicode string to something that expects a simple ASCII string? Also note, that LPBYTE is porbably not recognized as a string by the debugger, thus it will only show you the pointer's value (the address it is pointing at) and maybe the one byte it is pointing at.

              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

              A Offline
              A Offline
              amit code
              wrote on last edited by
              #7

              hi.. thanks for reply. You are right in your first point, when i convert cstring to string and than pass it to LPBYTE than whole data is being assigned and yes we can see the whole data during debug in lpbyte but during conversation from cstring to string data not written in english language being wrongly modified and there what i am getting problem. Thats why I am trying to convert cstring directly to lpbyte. Thanks

              amit

              C 1 Reply Last reply
              0
              • A amit code

                hi.. thanks for reply. You are right in your first point, when i convert cstring to string and than pass it to LPBYTE than whole data is being assigned and yes we can see the whole data during debug in lpbyte but during conversation from cstring to string data not written in english language being wrongly modified and there what i am getting problem. Thats why I am trying to convert cstring directly to lpbyte. Thanks

                amit

                C Offline
                C Offline
                Code o mat
                wrote on last edited by
                #8

                Then -as other people already pointed out- please show us how you actually do the conversion.

                > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                1 Reply Last reply
                0
                • A amit code

                  I want to convert a cstring into LPBYTE but each time i convert it only first character get stored in the LPBYTE and rest of the string is truncated. Thanks

                  amit

                  _ Offline
                  _ Offline
                  _Superman_
                  wrote on last edited by
                  #9

                  Try this.

                  BYTE string[MAX_PATH];

                  ::WideCharToMultiByte(CP_ACP, 0, (LPCTSTR)cstring, -1, (LPSTR)string, MAX_PATH, 0, 0);

                  «_Superman_» I love work. It gives me something to do between weekends.

                  A D 2 Replies Last reply
                  0
                  • _ _Superman_

                    Try this.

                    BYTE string[MAX_PATH];

                    ::WideCharToMultiByte(CP_ACP, 0, (LPCTSTR)cstring, -1, (LPSTR)string, MAX_PATH, 0, 0);

                    «_Superman_» I love work. It gives me something to do between weekends.

                    A Offline
                    A Offline
                    amit code
                    wrote on last edited by
                    #10

                    Thanks for reply.. i have tried your suggestion but it fails to convert character of other language. Meanwhile i found a workaround solution of this one.

                    amit

                    1 Reply Last reply
                    0
                    • _ _Superman_

                      Try this.

                      BYTE string[MAX_PATH];

                      ::WideCharToMultiByte(CP_ACP, 0, (LPCTSTR)cstring, -1, (LPSTR)string, MAX_PATH, 0, 0);

                      «_Superman_» I love work. It gives me something to do between weekends.

                      D Offline
                      D Offline
                      Destiny777
                      wrote on last edited by
                      #11

                      Nice change to ACTUALLY see a code example that actually works... Too many times I have to weed out the trash where people don't have the common courtesy of showing an actual code example. They beat the dead horse to death without any clue to help those that aren't intimately familiar with all the ins and outs of C! Thanks "Superman"! :) --- Most of my programming of the last 5 to 10 years has been in Visual Basic where strings are strings. C++ has so damn many string types that it is very easy to get confused when converting the different flavors of strings to anything and back. If I had my way, more people would learn to program in Assembly where data is data and you have to determine what to do with it. My first programming job for the first 5 to 7 years was purely in Assembly Language. I learned a bunch of things very quickly that way. We all too lazy in the last 20 years it seems when programming. Bill G. Senior Software Engineer / Systems Analyst for over 32 years. Age 53

                      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