How to change the CP_ACP(0) of windows ANSI apis in an application?

浪尽此生 提交于 2020-01-11 09:17:49

问题


I try to draw text using a dll library which has only interfaces of ANSI version encapsulated windows ANSI apis, but I need to store string data using utf-8. I don't want to convert strings using MultiByte/WideChar functions so I want an approach to change the CP_ACP in my application, so that I can input string data into ANSI apis. thanks.

ps: I don't to change the system default codepage.


回答1:


CP_ACP represents the system Ansi codepage. You cannot change that on a per-process or per-thread basis. It is a system-wide setting. If the DLL really is dependant on CP_ACP internally, then you have no choice but to convert your from/to UTF-8 whenever you interact with the DLL.




回答2:


"How to change the CP_ACP?" - "I don't (want) to change the system default codepage."

Well, you have to choose. CP_ACP is the system default codepage.




回答3:


UTF8 is not a codepage, and as codepages only make sense to ANSI functions, you can't do what you're asking.

If you want to store string as UTF8, you WILL need to convert from the ANSI of your app to unicode (wide char) using MultiByteToWideChar() then use WideCharToMultiByte() to convert to UTF8.

Alternatively, update you app to use unicode/wide strings internally, and convert as needed.



来源:https://stackoverflow.com/questions/9033825/how-to-change-the-cp-acp0-of-windows-ansi-apis-in-an-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!