December 12th, 2025
0 reactions

Resolving an ambiguity in the Windows clipboard automated text conversion table

Last time, we encountered a mystery where the synthesis of CF_OEM­TEXT from CF_TEXT did not use Ansi­To­Oem. Today we will begin the investigation.

Recall that we have a table showing how Windows synthesizes each of the various text formats from the other two. 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?

The preference table is

To get First try Then try And then try
CF_TEXT CF_TEXT CF_UNICODETEXT CF_OEMTEXT
CF_OEMTEXT CF_OEMTEXT CF_UNICODETEXT CF_TEXT
CF_UNICODETEXT CF_UNICODETEXT CF_TEXT CF_OEMTEXT

In words, first look for a perfect match. If that’s not available, then try (in order) CF_UNICODE­TEXT, then CF_TEXT, then CF_OEM­TEXT. (One of those last three checks is redundant with the perfect match check.)

Combining that with our previous table produces this conversion table with priorities:

To get First try Then try And then try
CF_TEXT CF_TEXT CF_UNICODETEXT + WC2MB(ANSI CP) CF_OEMTEXT + OemToAnsi
CF_OEMTEXT CF_OEMTEXT CF_UNICODETEXT + WC2MB(OEM CP) CF_TEXT + AnsiToOem
CF_UNICODETEXT CF_UNICODETEXT CF_TEXT + MB2WC(ANSI CP) CF_OEMTEXT + MB2WC(OEM CP)

Again, “ANSI CP” means “the code page reported by calling Get­Locale­Info with the LCID in the CF_LOCALE clipboard format, and the LOCALE_IDEFAULT­ANSI­CODE­PAGE locale attribute”. Similarly for “OEM CP”, using LOCALE_IDEFAULT­CODE­PAGE instead of LOCALE_IDEFAULT­ANSI­CODE­PAGE.

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’ll talk about it next time.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments