After more research and writing a couple of demo apps in both C++ and C#, I am revising this question to better target the issue that I have been seeing.
Problem statement: I have a (Visual Studio) MFC Unicode app that is used by some people in Japan. One of the app's functions outputs an enhanced metafile to the clipboard for pasting into other applications. The MFC app is an OLE server app and uses COleServerItem::CopyToClipboard to add the metafile to the clipboard. Some of the text in the metafile use glyphs with character codes > 127. On a Japanese version of Windows (with a en-US language pack installed), those glyphs do not render properly when pasted into another application. Instead of the expected symbols, they are rendered as some latin chars in some other font. Doesn't make any difference what font is used.
The following is what a demonstration MFC app draws to the screen using special characters from the Symbol font:
https://horoscope.blob.core.windows.net/japanese-os-clipboard-problem/FaithfulRendering-cropped-50%25.png[
^]
When copying and pasting the above enhanced metafile into WordPad on a Japanese version of windows, the result is:
https://horoscope.blob.core.windows.net/japanese-os-clipboard-problem/RenderedImproperly-cropped-33%25.png[
^]
If I change the strings that use the glyphs from CString(wchar_t) to CStringA (char), and use TextOutA instead of the Unicode verison, then the glyphs do render properly!
An additional workaround, instead of using COleServerItem::CopyToClipboard, is to "manually" put data on the clipboard using standard C++ clipboard functions like OpenClipboard, EmptyClipboard, SetClipboardData, CloseClipboard. This also fixes the problem without having to change the strings in the metafile to ANSI. So one might think that the problem is in COleServerItem::CopyToClipboard.
However, there is a related problem that doesn't involve the clipboard. The app uses a legacy MSFlexGrid OCX. The com object uses OLE which is Unicode, but on a Japanes Windows system, when the grids are displayed on screen, the special glyphs (extended ascii char codes > 127) also render improperly.
Note that if one just copies and pastes plain text in whatever font, then there isn't a problem.
I have created a Git repository with a Visual Studio MFC solution that demonstrates the problem at
GitHub - brewerpm/JapaneseWinClipboardUnicodeProblem: VS MFC solution to demonstrate using extended ASCII chars with clipboard and OLE on Japanese version of Windows[
^] .
Other things I have tried (1) Adding a CF_LOCALE record to the clipboard that specifies "en-US"; (2) specifying the locale as "en-US" using _wsetlocale(LC_ALL, L"en-US") at the beginning of the program (InitInstance) and (3) setting the codepage to Western 1252.
pmBrewer
What I have tried:
(1) Adding a CF_LOCALE record to the clipboard that specifies "en-US"; (2) specifying the locale as "en-US" using _wsetlocale(LC_ALL, L"en-US") at the beginning of the program (InitInstance) and (3) setting the codepage to Western 1252.