Compiling Unicode text documents in WinCE

Source: Internet
Author: User

When running a program, you usually need to record some log files. The common method is to output the program running information to the TXT text.

The Unicode is used in windows and ANSI.

In wince, Unicode dual-byte encoding is used by default, instead of the ANSI single-byte of the system,

Therefore, when writing TXT text, you need to make some settings before you can view it without garbled characters.

 

To put it bluntly, we need to write Unicode-encoded TXT text.

The difference between unicode encoded text and ANSI encoded text is that the first two bytes of Unicode text are FF Fe.

Therefore, when creating a text in wince, you must first write two bytes of content FF Fe, indicating that the text is Unicode.

 

When calling writefile, you also need to note the length of the string to be written.

Since Unicode is dubyte and writefile is calculated in bytes, the Written string is multiplied by 2.

Because windows is low-byte front and high-byte back, if you set the Unicode flag

Word wunicodeflag = 0 xfeff;

 

Boolwritetofile (lpctstr lpdata) <br/>{< br/> bool bresult = false; <br/> handle hfile; <br/> DWORD dwbytewrite; <br/> tchar szbuf [256]; </P> <p> hfile = createfile (text ("// regrecord.txt"), <br/> generic_read | generic_write, <br/> 0, // share mode <br/> null, // lpsecurityattribute <br/> open_always, // create disposition <br/> file_attribute_normal, <br/> null); <br/> If (hfile = invalid_handle_value) <br/> {<br/> Stringcchprintf (szbuf, 256, text ("writefile: % d"), getlasterror (); <br/> MessageBox (null, szbuf, text ("error "), mb_iconerror); <br/> return bresult; <br/>}< br/> // write the Unicode flag <br/> If (getlasterror ()! = Error_already_exists) <br/>{< br/> word wunicodeflag; <br/> wunicodeflag = 0 xfeff; <br/> If (! Writefile (hfile, & wunicodeflag, sizeof (Word), & dwbytewrite, null) <br/>{< br/> stringcchprintf (szbuf, 256, text ("writefile: % d "), getlasterror (); <br/> MessageBox (null, szbuf, text (" error "), mb_iconerror ); <br/>}< br/> setfilepointer (hfile, 0, null, file_end); </P> <p> If (! Writefile (hfile, <br/> lpdata, <br/> _ tcslen (lpdata) * sizeof (tchar), // bytes wait to write. <br/> & dwbytewrite, <br/> null) <br/> {<br/> stringcchprintf (szbuf, 256, text ("writefile: % d "), getlasterror (); <br/> MessageBox (null, szbuf, text ("error"), mb_iconerror ); <br/>}< br/> else <br/>{< br/> bresult = true; <br/>}</P> <p> closehandle (hfile ); <br/> return bresult; <br/>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.