如何以编程方式确定Windows的当前默认代码页? [英] How can I programmatically determine the current default codepage of Windows?

查看:627
本文介绍了如何以编程方式确定Windows的当前默认代码页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将VB6应用程序的字符串输出的编码转换为特定的编码。

I have to convert the encoding of a string output of a VB6 application to a specific encoding.

问题是,我不知道字符串,因为:

The problem is, I don't know the encoding of the string, because of that:


根据VB6文档,当访问某些API函数时,内部Unicode字符串转换为ANSI字符串,

According to the VB6 documentation when accessing certain API functions the internal Unicode strings are converted to ANSI strings using the default codepage of Windows.

因此,字符串输出的编码在不同系统上可能不同,但我必须知道它来执行转换。

Because of that, the encoding of the string output can be different on different systems, but I have to know it to perform the conversion.

如何读取默认代码页使用Win32 API或 - 如果没有其他方式 - 通过阅读注册表?

How can I read the default codepage using the Win32 API or - if there's no other way - by reading the registry?

推荐答案

使用 GetACP - 返回默认代码页的Win32 API调用! (默认代码页通常称为ANSI)

It could be even more succinct by using GetACP - the Win32 API call for returning the default code page! (Default code page is often called "ANSI")

int nCodePage = GetACP(); 

也有许多API调用(例如 MultiByteToWideChar )接受常量值 CP_ACP (零),总是表示使用系统代码页。所以你实际上可能不需要知道当前的代码页,取决于你想要做什么。

Also many API calls (such as MultiByteToWideChar) accept the constant value CP_ACP (zero) which always means "use the system code page". So you may not actually need to know the current code page, depending on what you want to do with it.

这篇关于如何以编程方式确定Windows的当前默认代码页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆