{"id":25123,"date":"2007-09-14T10:00:00","date_gmt":"2007-09-14T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2007\/09\/14\/the-code-page-on-the-server-is-not-necessarily-the-code-page-on-the-client\/"},"modified":"2007-09-14T10:00:00","modified_gmt":"2007-09-14T10:00:00","slug":"the-code-page-on-the-server-is-not-necessarily-the-code-page-on-the-client","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20070914-00\/?p=25123","title":{"rendered":"The code page on the server is not necessarily the code page on the client"},"content":{"rendered":"<p>It&#8217;s not enough to choose a code page. You have to choose the right code page.<\/p>\n<blockquote class=\"m\"><p>  We have a system that reformats and reinstalls a network client computer each time it boots up. The client connects to the server to obtain a loader program, and the loader program then connects to the server to download the actual operating system. If anything goes wrong, the server sends an error message to the client, which is displayed on the screen while it&#8217;s still in character mode. (No Unicode available here.) <\/p>\n<p> Initially, we used <code>FormatMessageA<\/code> to generate the error message, but somebody told us we should use <code>FormatMessageW<\/code> followed by <code>WideCharToMultiByte(CP_OEM)<\/code>. I&#8217;m not sure whether this is a valid suggestion, because the client hasn&#8217;t yet installed Unicode support so it only is capable of displaying 8-bit text, and using <code>CP_OEM<\/code> will use the OEM code page on the server, which doesn&#8217;t necessarily match the OEM code page on the client. <\/p>\n<p> What is the correct way of generating the error message string? <\/p>\n<\/blockquote>\n<p> Now, mind you, the argument against using <code>CP_OEM<\/code> is the same argument against using <code>FormatMessageA<\/code>! In neither case are you sure that the code page on the server matches the code page on the client. If <code>CP_OEM<\/code> is wrong, then so too is <code>FormatMessageA<\/code> (which uses <code>CP_ACP<\/code>).\n The correct solution is to use <code>FormatMessageW<\/code> followed by <code>WideCharToMultiByte(x)<\/code>, where <code>x<\/code> is the OEM code page of the client. You need to get this information from the client to the server somehow so that the server knows what character set the client is going to use for displaying strings.<\/p>\n<p> There&#8217;s really nothing deep going on here. If you&#8217;re going to display an 8-bit string, you need to use the same code page when generating the string as you will use when displaying it. <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/03\/01\/541266.aspx\"> Keep your eye on the code page<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s not enough to choose a code page. You have to choose the right code page. We have a system that reformats and reinstalls a network client computer each time it boots up. The client connects to the server to obtain a loader program, and the loader program then connects to the server to download [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-25123","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>It&#8217;s not enough to choose a code page. You have to choose the right code page. We have a system that reformats and reinstalls a network client computer each time it boots up. The client connects to the server to obtain a loader program, and the loader program then connects to the server to download [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/25123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=25123"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/25123\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=25123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=25123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=25123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}