CFile write unicode text in wince
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: CFile write unicode text in wince

Hybrid View

  1. #1
    Join Date
    Sep 2010
    Posts
    4

    CFile write unicode text in wince

    Hello everybody

    I'm trying to write some texts into html file using CFile::Write function. Below is what I'm using.

    mFile.Write(myString,myString.GetLength() * sizeof(TCHAR));

    As a result in the file however I get something like this:
    0 1 : 2 2 : 0 6 . 0 0 T a e o t u i e o e

    This should be written as:
    01:22:06.00 Trace output file open

    Any idea what the problem could be?

    Thanks in advance!

  2. #2
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: CFile write unicode text in wince

    Hi,

    You are writing the file as unicode, but when you view it are opening it as ascii (one byte per character.)

    Since it's HTML, you probably want to write it as UTF8, and can use WideCharToMultiByte to convert to that. Use google to find a suitable sample.

    Alan

  3. #3
    Join Date
    Sep 2010
    Posts
    4

    Re: CFile write unicode text in wince

    Just to make sure, you meant MultiByteToWideChar conversion, correct?

  4. #4
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: CFile write unicode text in wince

    Hi,

    In fact, I did mean WideCharToMultiByte. It sounds wrong, but WideChar is 16bit, MultiByte is 8bit.

    Alan

  5. #5
    Join Date
    Sep 2010
    Posts
    4

    Re: CFile write unicode text in wince

    Thanks for the replies Alan

    So I modified the codes as follows, but I'm still getting the same result


    char StringToWrite[500];

    WideCharToMultiByte(CP_ACP,NULL,myString,-1,StringToWrite,sizeof(StringToWrite),NULL,NULL);

    mFile.Write(StringToWrite,StringToWrite.GetLength() * sizeof(TCHAR));

    Any ideas?

  6. #6
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: CFile write unicode text in wince

    Hi,

    This looks wrong: StringToWrite.GetLength(), did you show your exact code after changing it?

    Alan

Tags for this Thread

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