如何在非 unicode c++ 中获取和传递阿拉伯字符环境

发布于 2024-09-08 01:59:53 字数 536 浏览 8 评论 0原文

我目前正在开发一个用 C++ 编写的项目,并使用 True OLE DBGrids 和 MS Access 后端。这一切都运行良好,直到现在我们需要能够将 GUI 转换为显示阿拉伯字符。 DBGrid 不使用 Unicode,因此我需要一种在不使用 Unicode 的情况下显示数据库中的字符的方法。目前,我已将区域语言设置设置为阿拉伯语,当我这样做时,我可以强制网格显示阿拉伯字符,但我无法通过代码来做到这一点。我需要能够在运行时在英语和阿拉伯语之间进行更改。我可以从数据库中提取数据,然后使用以下代码将其转换为非 Unicode:

_bstr_t tmp(vHolder.bstrVal, FALSE);   //wrap the BSTR
CString Caption(static_cast<const char*>(tmp));  //convert it
RetCaption = Caption;

这样我就可以将阿拉伯语发布到 AfxMessageBox 并正确显示,但我似乎无法让网格接受非 Unicode 字符并正确显示它们。

有什么想法吗?

I'm currently working on a project that is written in C++ and uses True OLE DBGrids with a MS Access backend. This all works well until now we need to be able to convert our GUI to display Arabic characters. The DBGrids do not use Unicode so I need a way to display the characters from the database without using Unicode. Currently I have set the Regional language settings to Arabic and when I did this I can force the grids to display the Arabic characters but I can't do it through code. I need to be able to change between English and Arabic at run time. I can pull the data out of the database and then convert it to non-Unicode using the following code:

_bstr_t tmp(vHolder.bstrVal, FALSE);   //wrap the BSTR
CString Caption(static_cast<const char*>(tmp));  //convert it
RetCaption = Caption;

With this I can then post the Arabic to an AfxMessageBox and it displays correctly but I can't seem to get the grids to accept the non-Unicode characters and display them correctly.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不一样的天空 2024-09-15 01:59:53
CString Caption(static_cast<const char*>(tmp));  //convert it

那不会转换它。如果 tmp 包含英文文本,它会生成单个字符。如果包含阿拉伯语文本,则还有吉贝尔土地上的一句俗语。从 OLE 自动化和您使用的 DBGrid 使用的 UTF-16 转换为 8 位字符无法通过强制转换完成,它需要转换函数。类似于 WideCharToMultiByte 或 OLE2A。

仅当线程的代码页与字符串中使用的字符集匹配时,此类转换才会重现清晰的文本。如果网格显示阿拉伯语,而您的线程或转换为英语的代码页只会产生一堆问号。

如果您不想让您的代码启用 Unicode,那么您就无法在字符集之间动态切换。您运行此代码的操作系统在过去 17 年中一直支持它。

CString Caption(static_cast<const char*>(tmp));  //convert it

That doesn't convert it. It produces a single character if tmp contains English text. And a common saying from the land of Jibber if it contains Arabic text. Converting from UTF-16, as used by OLE Automation and the DBGrid you are using to 8-bit characters cannot be done with a cast, it requires a conversion function. Like WideCharToMultiByte or OLE2A.

Such a conversion will only reproduce legible text when the code page for the thread matches the character set used in the string. Which, if the grid shows Arabic and either your thread or the code page you convert to is English produces nothing but a bunch of question marks.

If you don't want to Unicode-enable your code then you can't switch between character sets on the fly. The operating system you are running this code on has supported it for the past 17 years.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文