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. HELP: UNICODE conversion sprung up problems with CString & CHARFORMAT2

HELP: UNICODE conversion sprung up problems with CString & CHARFORMAT2

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studiocom
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.
  • A Offline
    A Offline
    andwan0
    wrote on last edited by
    #1

    I've dug up SteveKing's old article SpellEdit: SpellEdit[^] Originally it was made for Visual Studio 7.1 (2003) but I managed to fiddle with it to get it compiling/working under Visual Studio 6.0 (because that's what I have). Everything is working however the project is non-UNICODE. So I converted the project into UNICODE and now I get lots of build errors, such as:

    error C2664: 'spell' : cannot convert parameter 1 from 'class CString' to 'const char *'

    The whole MySpell library/code uses char * everywhere... and even HunSpell uses char * everywhere too. So how come previously (in non-UNICODE) there was an implicit conversion between CString & const char *, but after changing project to UNICODE I get this error. PS: This is not problem about converting CString to char * - even though I've tried this, it just doesn't work.

    J 1 Reply Last reply
    0
    • A andwan0

      I've dug up SteveKing's old article SpellEdit: SpellEdit[^] Originally it was made for Visual Studio 7.1 (2003) but I managed to fiddle with it to get it compiling/working under Visual Studio 6.0 (because that's what I have). Everything is working however the project is non-UNICODE. So I converted the project into UNICODE and now I get lots of build errors, such as:

      error C2664: 'spell' : cannot convert parameter 1 from 'class CString' to 'const char *'

      The whole MySpell library/code uses char * everywhere... and even HunSpell uses char * everywhere too. So how come previously (in non-UNICODE) there was an implicit conversion between CString & const char *, but after changing project to UNICODE I get this error. PS: This is not problem about converting CString to char * - even though I've tried this, it just doesn't work.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      A quote from the MySpell link of the SpellEdit article:

      Quote:

      MySpell has been replaced with hunspell starting with OpenOffice.org 2.0.2. Hunspell builds on MySpell but supports Unicode and adds several other useful features.

      So you can't use MySpell with Unicode builds because it supports only ANSI character sets. Hunspell has Unicode support but uses UTF-8 strings while Windows uses UTF-16. So Windows strings must be converted to UTF-8 before passing them to the spell checker. With UTF-8, strings are still passed as char* because a single character is encoded as sequences of bytes with variable length while UTF-16 charcters are represented by two bytes (wchar_t). When using CString objects, they will be CStringA or CStringW according to the Unicode setting of your project. You may use CStrings to convert between ANSI and Unicode:

      LPCSTR lpszAnsi = "ANSI text";
      LPWCSTR lpszWide = L"Unicode text";
      CStringA strA = lpszWide; // Converts to Unicode
      CStringW strW = lpszAnsi; // Converts to Unicode

      But for UTF-8 conversions, you must use WideCharToMultiByte() and MultiByteToWideChar(). You may have a look at http://sourceforge.net/projects/hunspell/files/Misc/RichEdit/[^] which implements spell checking for a RichEdit control using Hunspell.

      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