HELP: UNICODE conversion sprung up problems with CString & CHARFORMAT2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: HELP: UNICODE conversion sprung up problems with CString & CHARFORMAT2

  1. #1
    Join Date
    Mar 2009
    Posts
    15

    HELP: UNICODE conversion sprung up problems with CString & CHARFORMAT2

    I converted an old example code (SteveKing's SpellEdit):

    SpellEdit[^]

    to UNICODE. Also 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 fine in 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.

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: HELP: UNICODE conversion sprung up problems with CString & CHARFORMAT2

    You have to use wchar_t type instead of a char in a UNICODE build.
    To make your code both UNICODE and ANSI aware - use _T() macro and generic names for C-runtime functions used for string operations.
    See:
    http://msdn.microsoft.com/en-us/library/2dax2h36.aspx
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx
    http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2009
    Posts
    15

    Re: HELP: UNICODE conversion sprung up problems with CString & CHARFORMAT2

    Does this mean I have to change the whole of 3rd-party library MySpell & HunSpell?

    I thought HunSpell can support UNICODE (because it states it can)... but the source code still works with char *

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: HELP: UNICODE conversion sprung up problems with CString & CHARFORMAT2

    I have no idea what these 3rd-party library MySpell & HunSpell are and whether they can or cannot support UNICODE.
    If they cannot then you will need to convert your unicode strings to ANSI and v.v. using WideCharToMultiByte/MultiByteToWideChar APIs
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 1999
    Posts
    27,427

    Re: HELP: UNICODE conversion sprung up problems with CString & CHARFORMAT2

    Quote Originally Posted by andwan0 View Post
    error C2664: 'spell' : cannot convert parameter 1 from 'class CString' to 'const char *'
    Converting to Unicode doesn't just mean setting a project option to Unicode. Did you change the libraries also to a Unicode version of the libraries you're using? A library built for ANSI strings cannot magically change into one that handles Unicode strings without some sort of changes, either another version of the library, or the library contains function calls that are Unicode specific, etc.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center