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. Switching TCHAR to UTF-8

Switching TCHAR to UTF-8

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorialquestion
2 Posts 2 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.
  • S Offline
    S Offline
    SanShou
    wrote on last edited by
    #1

    Hey all... I am trying to write out a Japanese text string in a data file which was originally specified for ANSI text and used across several applications. Basically what was suggested was that I use UTF-8 to write out the text strings and read them back in. One of the constraints is that the current applications that read English only should still be able to read English data if this application writes it. However the old applications can punt on the Japanese until they are also updated. I can figure out how to write from MBCS to UTF-8: #ifndef UNICODE MultiByteToWideChar(CP_UTF8, dwFlags, lpMBCSStr, cbMBCS, lpWCStr, cchWCStr) #endif However we normally build in UNICODE using TCHAR, and it is normally UTF-16. However I just want to convert this one string from UTF-16 to UTF-8. Anyone ever done this? You can also just call me insane and stupid as long as you can suggest a better approach. I don't mind being insulted if I can learn something. :-D Brian If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life.

    M 1 Reply Last reply
    0
    • S SanShou

      Hey all... I am trying to write out a Japanese text string in a data file which was originally specified for ANSI text and used across several applications. Basically what was suggested was that I use UTF-8 to write out the text strings and read them back in. One of the constraints is that the current applications that read English only should still be able to read English data if this application writes it. However the old applications can punt on the Japanese until they are also updated. I can figure out how to write from MBCS to UTF-8: #ifndef UNICODE MultiByteToWideChar(CP_UTF8, dwFlags, lpMBCSStr, cbMBCS, lpWCStr, cchWCStr) #endif However we normally build in UNICODE using TCHAR, and it is normally UTF-16. However I just want to convert this one string from UTF-16 to UTF-8. Anyone ever done this? You can also just call me insane and stupid as long as you can suggest a better approach. I don't mind being insulted if I can learn something. :-D Brian If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life.

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      MultiByteToWideChar() is the right way to convert from UTF-16 to UTF-8. It doesn't matter what your UNICODE setting is because that API's input is always UTF-16 and the output is always a multi-byte encoding. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ----

      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