问题标签 [mbcs]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
360 浏览

c++ - 将字符转换为 UTF-8 背后的逻辑

我有以下代码,代码中的注释说它将任何大于7FUTF-8 的字符转换。我对此代码有以下问题:

  1. 这段代码是如何工作的?
  2. 我正在使用的当前 Windows 代码页对放置的字符有任何影响Buffer吗?
0 投票
0 回答
97 浏览

winapi - 在什么情况下 EDIT 控件会将 MBCS 视为 UNICODE?

我正在使用 MBCS 维护一个大型遗留应用程序构建。

在使用日语作为系统区域设置和英语作为 UI 区域设置的 Windows 7 系统上,我遇到了一个问题,即编辑控件的选择位置返回不正确。我在日本安装的 XP 和 Windows 7 上进行了测试,结果相同。

[codesnippet]

在字符串末尾使用克拉,这会产生输出

字符串'未定义'选择[3,3],unicode?错误的

到底会发生什么?我已经构建了一个小测试应用程序,它可以像我期望的那样工作,产生输出

字符串'未定义'选择[6,6],unicode?错误的

它是一个 MBCS 版本sizeof(TCHAR) == 1,我无法切换到 UNICODE,因为它是一个遗留应用程序。

0 投票
3 回答
1811 浏览

c++ - 如何从 UNICODE 应用程序写入 MBCS 文件?

我的问题似乎让人们感到困惑。这是具体的:

我们的代码执行以下操作:

在 MBCS 构建目标下,以上代码为代码页 932 生成了一个正确编码的文件(假设 932 是运行此代码页时的系统默认代码页)。

在 UNICODE 构建目标下,上面会产生一个充满 ???? 的垃圾文件。

我想定义一个符号,或使用编译器开关,或包含一个特殊的头文件,或链接到给定的库,以使上述内容在构建目标为 UNICODE 时继续工作而不更改源代码。

这是曾经存在的问题:

FILE*流可以在 t(ranslated) 或 b(inary) 模式下打开。桌面应用程序可以编译为 UNICODE 或 MBCS(在 Windows 下)。

如果我的应用程序是为 MBCS 编译的,那么将 MBCS 字符串写入“wt”流会生成一个格式正确的文本文件,其中包含系统代码页的 MBCS 文本(即“用于非 Unicode 软件的代码页”)。

因为我们的软件通常使用大多数字符串和流函数的 _t 版本,所以在 MBCS 构建中,输出主要由 puts(pszMBString)或类似的东西处理putc。由于 pszMBString已经在系统代码页中(例如,在日本机器上运行时为 932),字符串是逐字写出(尽管行终止符被自动按摩putsgets

但是,如果我的应用程序是为 UNICODE 编译的,那么将 MBCS 字符串写入“wt”流会导致垃圾(大量“?????”字符)(即,我将 UNICODE 转换为系统的默认代码页,然后写入例如,使用 fwrite(pszNarrow, 1, length, stream)) 将其发送到流。


我可以以二进制模式打开我的流,在这种情况下,我会得到正确的 MBCS 文本......但是,行终止符将不再是 PC 样式的 CR+LF,而是只会是 UNIX 样式的 LF。这是因为在二进制(非翻译)模式下,文件流不处理 LF->CR+LF 翻译。


但我真正需要的是能够生成与为 MBCS 编译时能够生成的完全相同的文件:使用系统代码页的正确行终止符和 MBCS 文本文件。

显然,我可以自己手动调整行终止符并使用二进制流。然而,这是一种非常具有侵入性的方法,因为我现在必须在整个系统中找到写入文本文件的每一段代码,并对其进行修改,以便它能够正确地完成所有这些工作。让我大吃一惊的是,UNICODE 目标比我们过去使用的 MBCS 目标更愚蠢/能力更差!当然有一种方法可以切换 C 库以显示“按原样输出窄字符串但正确处理行终止符,就像您在 MBCS 构建中所做的那样”?!

0 投票
3 回答
47742 浏览

c++ - 使用 Visual Studio 构建 MFC C++ 项目时出现 MBCS 错误

我使用 Visual Studio 打开了现有的 MFC 项目,并且在构建时收到以下错误消息:

这是关于什么的?

0 投票
2 回答
750 浏览

python - Python变音字符问题 - 需要mbcs,是否有更好的方法来处理所有字符

我在使用 Python 脚本打开包含变音符号的文件时遇到问题。自然地,我认为我可以用 unicode utf8 修复来纠正这个问题,但不是这样......

我最终使用了mbcs (默认为 cp1252)

然后我写了这个我希望写得更干净的声明,

0 投票
1 回答
6952 浏览

c++ - 无法将 CStringW 转换为 CStringA

我正在做一个项目,在该项目中我遇到了一个问题,即转换CStringWCStringA多字节字符串(如日语)。

我正在使用LoadString()方法从字符串资源中加载字符串。我尝试了以下代码,但它似乎不起作用。

我也试过 wcstombs()了。

谁能告诉我如何转换CStringWCString?提前致谢。

0 投票
1 回答
89 浏览

c++ - 读取注册表值 32 位?

我有以下为 MBCS 编译的代码。

  • 如何使代码也适用于 32 位计算机?
  • 如何将返回值放在一个简单的字符串中?前任; 字符串名称值 = GetRegistry(_T("name"));
0 投票
5 回答
3654 浏览

python - 在 windows 8.1 上使用 Django 的 manage.py runserver 出错

我在任何地方都找不到这个退出代码,但希望你们中的一个可以帮助我,或者让我知道这是否是 python/Django 中的错误。

无论如何,首先是堆栈跟踪:

请忽略奇怪的文件路径,我什至只是尝试将它直接放在 C:\ 上。

这里还有另一个可能类似的 Stackoverflow 问题:UnicodeEncodeError when using the compile function但它不像我使用的文件路径使用任何非英文字符。我在那里尝试了几个解决方案,但没有奏效。

运行之前在 2.7.x 中测试过的 python 3.4.1 也不起作用。在 linux(Ubuntu)上运行良好。

django 项目没有什么特别之处,因为它只是一个空的 startproject 项目。

0 投票
2 回答
905 浏览

c++ - using either ofstream, or fstream open does not error and does not open the file

Using Visual Studio 2012 & with Project properties:

  1. Configuration Properties: General: Project Defaults:Character Set: Not Set
  2. Configuration Properties: C++: Language:Treat WChar_t as Built In Type: No

I use an ofstream with following snippet of code: Note: the path "C:\data" is valid for this example

If the file was not present in the directory, the file would be open, text written, etc. If the file already existed the file is not opened, not written to, etc. No exception occurred and no error code was found (in errno). While debugging internal to open() method, I found some internal open calls were trying to copy the filename string into wchar_t type and exited with an internal error of 13 (looking up MS Constants = Open Aborted).

MBCS has been deprecated so I don't want to be set to that. Only other option is Unicode which breaks half of my changes. Why can't I make use of the std io library??!!!

What is weirder still I had some of this working with second switch to no with 1st set to MBCS. The code worked though a lot of places in dealing with GUI contaniners such as CEdit, I had a lot superfluous code to convert from CString to string if I had to. If in essence the representation of CString is a const char* which is somewhat close to LPCTSTR (not quite). It "SHOULD" be somewhat "SIMPLE" to convert from CString to string. It is not because UNECESSARY complications of switches between UTF-8 and UTF-16 that I am not engaged in. I desire my char to be STRICTLY 1-BYTE.

What is the closest path through this madness? Do I go back to back to MBCS (even though deprecated) and change all the container methods from GetWindowText() to GetWindowTextA() for example or abandon the use of streams in Visual Studio, or what???

Please Advise, if you can... Any help would be appreciated. Thanks.

Maddog

ps: Please don't go to the trouble to convert me to embrace the full Wide environment in my code, when my product will not be sold in Asia or Arabia.

pps: one final note, I got into this because, I noted my initial install of Visual Studio 2012 defaulted to MBCS.

0 投票
1 回答
957 浏览

visual-c++ - VS 2013 中弃用 MBCS 对 MFC 的支持的副作用

我只是尝试在 VS2013 下编译一个旧的 MFC 应用程序。它抱怨非 Unicode MFC 应用程序已被弃用,并拒绝编译。这与该声明有关弃用对 MBCS 的支持的声明有些相反。到目前为止,字符集选项有三个选择:

  • 统一码
  • MBCS
  • 没有设置

就个人而言,我完全同意放弃对 MBCS 的支持——我既不想也不需要 MBCS。但我也不需要也不需要 Unicode - ANSI/ASCII 对我来说很好。因此,坚持从今以后每个 MFC 应用程序都必须使用 Unicode,并且(实际上)为平台提供支持所有可能语言的基础,无论其目标受众是谁,这似乎......极端。我错过了什么吗?我是否仍然可以编译没有在 VS2013 下指定字符集的 MFC 应用程序?