{"id":111862,"date":"2025-12-12T07:00:00","date_gmt":"2025-12-12T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111862"},"modified":"2025-12-18T09:57:48","modified_gmt":"2025-12-18T17:57:48","slug":"20251212-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20251212-00\/?p=111862","title":{"rendered":"Resolving an ambiguity in the Windows clipboard automated text conversion table"},"content":{"rendered":"<p>Last time, we encountered a mystery where <a title=\"Studying the various locale mismatch scenarios in Windows clipboard text format synthesis\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20251211-37\/?p=111858\"> the synthesis of <code>CF_<wbr \/>OEM\u00adTEXT<\/code> from <code>CF_<wbr \/>TEXT<\/code> did not use <code>Ansi\u00adTo\u00adOem<\/code><\/a>. Today we will begin the investigation.<\/p>\n<p>Recall that <a title=\"How does Windows synthesize CF_UNICODETEXT from CF_TEXT and vice versa?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20251209-00\/?p=111854\"> we have a table showing how Windows synthesizes each of the various text formats from the other two<\/a>. But in the case where the clipboard has two formats available, and you ask for the third, there are two ways that the third format could be synthesized: It could convert the first, or it could convert the second. How does Windows decide?<\/p>\n<p>The preference table is<\/p>\n<table style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>To get<\/th>\n<th>First try<\/th>\n<th>Then try<\/th>\n<th>And then try<\/th>\n<\/tr>\n<tr>\n<th>CF_TEXT<\/th>\n<td>CF_TEXT<\/td>\n<td>CF_UNICODETEXT<\/td>\n<td>CF_OEMTEXT<\/td>\n<\/tr>\n<tr>\n<th>CF_OEMTEXT<\/th>\n<td>CF_OEMTEXT<\/td>\n<td>CF_UNICODETEXT<\/td>\n<td>CF_TEXT<\/td>\n<\/tr>\n<tr>\n<th>CF_UNICODETEXT<\/th>\n<td>CF_UNICODETEXT<\/td>\n<td>CF_TEXT<\/td>\n<td>CF_OEMTEXT<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In words, first look for a perfect match. If that&#8217;s not available, then try (in order) <code>CF_<wbr \/>UNICODE\u00adTEXT<\/code>, then <code>CF_<wbr \/>TEXT<\/code>, then <code>CF_<wbr \/>OEM\u00adTEXT<\/code>. (One of those last three checks is redundant with the perfect match check.)<\/p>\n<p>Combining that with our <a title=\"How does Windows synthesize CF_UNICODETEXT from CF_TEXT and vice versa?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20251209-00\/?p=111854\"> previous table<\/a> produces this conversion table with priorities:<\/p>\n<table style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>To get<\/th>\n<th>First try<\/th>\n<th>Then try<\/th>\n<th>And then try<\/th>\n<\/tr>\n<tr>\n<th>CF_TEXT<\/th>\n<td>CF_TEXT<\/td>\n<td>CF_UNICODETEXT + WC2MB(ANSI CP)<\/td>\n<td>CF_OEMTEXT + OemToAnsi<\/td>\n<\/tr>\n<tr>\n<th>CF_OEMTEXT<\/th>\n<td>CF_OEMTEXT<\/td>\n<td>CF_UNICODETEXT + WC2MB(OEM CP)<\/td>\n<td>CF_TEXT + AnsiToOem<\/td>\n<\/tr>\n<tr>\n<th>CF_UNICODETEXT<\/th>\n<td>CF_UNICODETEXT<\/td>\n<td>CF_TEXT + MB2WC(ANSI CP)<\/td>\n<td>CF_OEMTEXT + MB2WC(OEM CP)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Again, &#8220;ANSI CP&#8221; means &#8220;the code page reported by calling <code>Get\u00adLocale\u00adInfo<\/code> with the LCID in the <code>CF_<wbr \/>LOCALE<\/code> clipboard format, and the <code>LOCALE_<wbr \/>IDEFAULT\u00adANSI\u00adCODE\u00adPAGE<\/code> locale attribute&#8221;. Similarly for &#8220;OEM CP&#8221;, using <code>LOCALE_<wbr \/>IDEFAULT\u00adCODE\u00adPAGE<\/code> instead of <code>LOCALE_<wbr \/>IDEFAULT\u00adANSI\u00adCODE\u00adPAGE<\/code>.<\/p>\n<p>If you stare at this table, you might notice something odd, possibly even disturbing. And that is part of the answer to the mystery. We&#8217;ll talk about it next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Who goes first?<\/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-111862","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Who goes first?<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111862","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=111862"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111862\/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=111862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}