December 8th, 2025
0 reactions

How does Windows synthesize CF_OEM­TEXT from CF_TEXT and vice versa?

Windows has three built-in text formats for the clipboard:

  • CF_UNICODE­TEXT: UTF-16 text.
  • CF_TEXT: 8-bit text in ANSI code page.
  • CF_OEM­TEXT: 8-bit text in OEM code page.

If you don’t provide all three formats, then the system will synthesize the missing ones from the ones you have. How does this work?

Believe it or not, we’re going to spend the rest of the week on this topic.

One thing to note is that the synthesis is done on demand. It is only when somebody asks for, say, CF_TEXT and the clipboard realizes that it has only CF_OEM­TEXT, that the clipboard creates the CF_OEM­TEXT on the fly. Once done, the result is cached so that it doesn’t have to be converted again.

Today’s conversion is the one that looks easiest on the surface: Converting CF_TEXT to CF_OEM­TEXT and back.

To convert CF_TEXT to CF_OEM­TEXT, Windows uses the AnsiToOem function. And to convert the other way, it uses the Oem­To­Ansi function.

These are legacy function names; the modern names are Char­To­Oem and Oem­To­Char. But I used the legacy names because that’s what they were called in 16-bit Windows, and that’s how the conversion was done in 16-bit Windows.

This was anticlimactic, but we’re just getting started. And when we get to the end, we’ll see that what looks like a simple answer is actually quite complicated.

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 CF_UNICODE­TEXT, which we’ll look at 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.

3 comments

Sort by :
  • skSdnW 1 hour ago · Edited

    If UTF-8 is selected as the ANSI codepage, you get it from CF_TEXT. If your app uses UTF-8 everywhere then it probably knows how to convert from UTF-16 already.

    (I have no idea why my replies don’t attach correctly to the person I’m replying to)

  • Igor Levicki 2 hours ago · Edited

    Hey Raymond, when will they be adding CF_UTF8TEXT?

    Also, when will Microsoft Teams stop putting large images as giant Base64 encoded sausages on the clipboard?

    A soul-crushing exercise: Try copying a large image from Microsoft Teams to another messenger app (Telegram, Viber, Signal, WhatsApp, etc), watch how it results in 1,000+ gibberish text messages when you paste it, and then have "fun" selecting and deleting them all.

    IMO, that's total Clipboard API abuse and should be blocked on the OS level. The least that could be done is to give user the control of the size of text pasted to clipboard and also...

    Read more
    • Antonio Rodríguez 36 minutes ago · Edited

      I agree that this is very inconvenient, and I'd consider it a bug in Teams (private clipboard formats were invented to solve this problem). But, how could this be controlled at the OS level without crippling the user? If a large amount of text is placed in the clipboard, probably it's the user who wanted to move it from one application to another (maybe they are copying a chapter of a book or something like that). The OS shouldn't restrict the clipboard just because some apps abuse its use.

      And no, the solution isn't showing an alert interrupting the workflow, which...

      Read more