{"id":111849,"date":"2025-12-08T07:00:00","date_gmt":"2025-12-08T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111849"},"modified":"2025-12-08T11:50:04","modified_gmt":"2025-12-08T19:50:04","slug":"20251208-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20251208-00\/?p=111849","title":{"rendered":"How does Windows synthesize <CODE>CF_<WBR>OEM&shy;TEXT<\/CODE> from <CODE>CF_<WBR>TEXT<\/CODE> and vice versa?"},"content":{"rendered":"<p>Windows has three built-in text formats for the clipboard:<\/p>\n<ul>\n<li><code>CF_<wbr \/>UNICODE\u00adTEXT<\/code>: UTF-16 text.<\/li>\n<li><code>CF_<wbr \/>TEXT<\/code>: 8-bit text in ANSI code page.<\/li>\n<li><code>CF_<wbr \/>OEM\u00adTEXT<\/code>: 8-bit text in OEM code page.<\/li>\n<\/ul>\n<p>If you don&#8217;t provide all three formats, then the system will synthesize the missing ones from the ones you have. How does this work?<\/p>\n<p>Believe it or not, we&#8217;re going to spend the rest of the week on this topic.<\/p>\n<p>One thing to note is that the synthesis is done on demand. It is only when somebody asks for, say, <code>CF_<wbr \/>TEXT<\/code> and the clipboard realizes that it has only <code>CF_<wbr \/>OEM\u00adTEXT<\/code>, that the clipboard creates the <code>CF_<wbr \/>TEXT<\/code> on the fly. Once done, the result is cached so that it doesn&#8217;t have to be converted again.<\/p>\n<p>Today&#8217;s conversion is the one that looks easiest on the surface: Converting <code>CF_<wbr \/>TEXT<\/code> to <code>CF_<wbr \/>OEM\u00adTEXT<\/code> and back.<\/p>\n<p>To convert <code>CF_<wbr \/>TEXT<\/code> to <code>CF_<wbr \/>OEM\u00adTEXT<\/code>, Windows uses the <code>AnsiToOem<\/code> function. And to convert the other way, it uses the <code>Oem\u00adTo\u00adAnsi<\/code> function.<\/p>\n<p>These are legacy function names; the modern names are <code>Char\u00adTo\u00adOem<\/code> and <code>Oem\u00adTo\u00adChar<\/code>. But I used the legacy names because that&#8217;s what they were called in 16-bit Windows, and that&#8217;s how the conversion was done in 16-bit Windows.<\/p>\n<p>This was anticlimactic, but we&#8217;re just getting started. And when we get to the end, we&#8217;ll see that what looks like a simple answer is actually quite complicated.<\/p>\n<p>Back in the days of 16-bit Windows, ANSI text and OEM text were the only two clipboard text formats, so there were only two possible conversions (one in each direction). Things get more complicated with the introduction of <code>CF_<wbr \/>UNICODE\u00adTEXT<\/code>, which we&#8217;ll look at next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Starting with the easy case, or at least it looks easy.<\/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-111849","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Starting with the easy case, or at least it looks easy.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111849","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=111849"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111849\/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=111849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}