setlocale() 不会影响 ConvertBSTRToString() 但系统范围的设置会影响吗?

发布于 2024-09-08 23:53:33 字数 975 浏览 1 评论 0原文

鉴于: 使用旧版 COM 库的 ASP.Net 应用程序 未使用 Unicode (MBCS) 构建的旧版 COM 库 运行所有程序的 Windows 2008 开发服务器

需要: 支持不同区域设置中的 Web 应用程序用户

测试:

1)我将服务器上的系统区域设置设置为俄语并测试了俄语输入。

.NET 将它们视为 UTF16,作为 BSTR 传递给 COM,COM 使用 ConvertBSTRToString 和当前区域设置(俄语)将其转换为 char*,将它们写入文件,将它们读取到文件,传递回 .NET 并获得正确的结果。

2)我将系统区域设置设置回美国/英语,向 ASP.NET 应用程序或 COM 本身添加代码以将区域设置显式设置为俄语,区域设置设置成功(我查询它并返回俄语),COM 接收 UTF -16 BSTR,使用ConvertBSTRToString将其转换为char*并得到问号“???”!

为什么??在此过程中进行系统范围的区域设置和调用 setlocale() 有什么区别?那么 setlocale 有什么意义呢? ConvertBSTRToString 是否使用当前语言环境以外的其他内容?

我还尝试

    System.Threading.Thread.CurrentThread.CurrentCulture = 
new System.Globalization.CultureInfo("ru-RU");

在 COM 对象的 ASP.NET 调用者内部执行操作,并尝试

setlocale(LC_ALL, "Russian");

        SetThreadLocale(
MAKELCID(MAKELANGID(LANG_RUSSIAN, SUBLANG_RUSSIAN_RUSSIA), SORT_DEFAULT));

在 COM 库内与 setlocale() 一起执行操作;没有效果。

我非常感谢对此的投入!

Given:
ASP.Net application which uses a legacy COM library
legacy COM library which is built without Unicode (MBCS)
Windows 2008 dev server on which it all runs

Needed:
support web app users in different locales

Test:

1) I set the system locale on the server to Russian and tested Russian inputs.

.NET treats them as UTF16, passes on to COM as BSTR, COM converts it to char* using ConvertBSTRToString and current locale (russian), writes them to file, reads them to file, passes back to .NET and getting correct results.

2) I set the system locale back to US/English, add code to either ASP.NET app or the COM itself to set locale to Russian explicitly, the locale is set successfully (I query it and get Russian back), COM receives UTF-16 BSTR, uses ConvertBSTRToString to convert it to char* and gets question marks "???"!

Why?? What's the difference between having system wide locale setting and calling setlocale() in the process? What is the point of setlocale then? Is ConvertBSTRToString using something other than current locale?

I have also tried doing

    System.Threading.Thread.CurrentThread.CurrentCulture = 
new System.Globalization.CultureInfo("ru-RU");

inside the ASP.NET caller of the COM object and tried doing

setlocale(LC_ALL, "Russian");

        SetThreadLocale(
MAKELCID(MAKELANGID(LANG_RUSSIAN, SUBLANG_RUSSIAN_RUSSIA), SORT_DEFAULT));

along side the setlocale() inside the COM library; no effect.

I would really appreciate inputs on that!

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

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

发布评论

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

评论(1

穿透光 2024-09-15 23:53:33

从文档中不清楚 ConvertBSTRToString() 使用什么来确定当前区域设置。但您可以非常确定它不是 setlocale() 设置的 CRT 区域设置。您几乎肯定需要调用 SetThreadLocale()。

使用 WideCharToMultiByte() 可以减少猜测。

It isn't clear from the docs what ConvertBSTRToString() uses to determine the current locale. But you can be pretty sure that it is not the CRT locale as set by setlocale(). You almost certainly need to call SetThreadLocale().

Use WideCharToMultiByte() to make it less of a guess.

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