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. convert wchar* to byte*

convert wchar* to byte*

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 Posts 3 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
    Rakesh5
    wrote on last edited by
    #1

    hi, can anyone suggest me how to convert wchar* to byte*... Thanks, Rakesh

    L 1 Reply Last reply
    0
    • R Rakesh5

      hi, can anyone suggest me how to convert wchar* to byte*... Thanks, Rakesh

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You can simply cast the pointer to PBYTE or BYTE*wchar_t buf[] = L"Hello World"; PBYTE pBytes = (PBYTE)buf;
      Best Wishes, -David Delaune

      R 1 Reply Last reply
      0
      • L Lost User

        You can simply cast the pointer to PBYTE or BYTE*wchar_t buf[] = L"Hello World"; PBYTE pBytes = (PBYTE)buf;
        Best Wishes, -David Delaune

        R Offline
        R Offline
        Rakesh5
        wrote on last edited by
        #3

        hey, its not converting fully... if i have wchar* q = "AJC"; when i convert it using ur method, PBYTE pbytes = (PBYTE)q; its giving pbytes as C alone... can u shed some light on it? Thanks, Rakesh

        L _ 2 Replies Last reply
        0
        • R Rakesh5

          hey, its not converting fully... if i have wchar* q = "AJC"; when i convert it using ur method, PBYTE pbytes = (PBYTE)q; its giving pbytes as C alone... can u shed some light on it? Thanks, Rakesh

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hi Rakesh,

          wchar* q = "AJC";

          This line of code is not correct. You cannot assign a pointer to an array of character value. It appears to me that you need some basic C/C++ tutorials. I found these on the net: http://www.cplusplus.com/doc/tutorial/ntcs/[^] http://www.cplusplus.com/forum/beginner/21/[^] http://www.cplusplus.com/doc/tutorial/pointers/[^] I think if you read these tutorials you may understand why your code does not work. Best Wishes, -David Delaune

          1 Reply Last reply
          0
          • R Rakesh5

            hey, its not converting fully... if i have wchar* q = "AJC"; when i convert it using ur method, PBYTE pbytes = (PBYTE)q; its giving pbytes as C alone... can u shed some light on it? Thanks, Rakesh

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

            wchar_t* q = L"AJC"; This creates a pointer to a wide character string. To convert this to BYTE* which is a multi-byte character string you can use the WideCharToMultiByte[^] API. But then a BYTE pointer will not suffice. You will need a BYTE array declaration. Something like - BYTE bytes[255];

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

            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