Bulletproofing MultiByteToWideChar

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
We have an app thats used in Europe, Latin America, Asia, and North America.
Recently weve experienced absolute an absolute nightmare dealing with Unicode.

My big question at this point is about that 1st parameter, the code page. Ideally, I would use the default codepage of the computer our app is being run on, but the documentation is a little confusing to me: (From Microsoft)<br/>

<table style="border-collapse:collapse; padding-bottom:20px; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; line-height:10.666666984558105px
<tbody>
<tr>
<td style="border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#dbdbdb; margin:10px; padding:10px 8px; color:#2a2a2a; vertical-align:top
<dl><dt> CP_ACP </dt></dl>
</td>
<td style="border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#dbdbdb; margin:10px; padding:10px 8px; color:#2a2a2a; vertical-align:top
<p style="margin-bottom:0px; line-height:18px The system default Windows ANSI code page.
<p style="margin-bottom:0px; line-height:18px Note This value can be different on different computers, even on the same network. It can be changed on the same computer, leading to stored data becoming irrecoverably corrupted. This
value is only intended for temporary use and permanent storage should use UTF-16 or UTF-8 if possible.
</td>
</tr>
</tbody>
</table>

<table style="border-collapse:collapse; padding-bottom:20px; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; line-height:10.666666984558105px
<tbody>
<tr>
<td style="border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#dbdbdb; margin:10px; padding:10px 8px; color:#2a2a2a; vertical-align:top
<dl><dt> CP_OEMCP </dt></dl>
</td>
<td style="border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#dbdbdb; margin:10px; padding:10px 8px; color:#2a2a2a; vertical-align:top
<p style="margin-bottom:0px; line-height:18px The current system OEM code page.
<p style="margin-bottom:0px; line-height:18px Note This value can be different on different computers, even on the same network. It can be changed on the same computer, leading to stored data becoming irrecoverably corrupted. This
value is only intended for temporary use and permanent storage should use UTF-16 or UTF-8 if possible.<br/>
<br/>
<br/>

</td>
</tr>
</tbody>
</table>
<br/>
Ive seen loads of examples using mostly CP_ACP or 0 as the first parameter. When would I ever using UTF-8 or UTF-16. How might CP-OEMCP or CP_ACP cause data corruption?


View the full article
 
Back
Top