在将ASCII字符串传递到Windows API函数之前将其转换为UTF-16 [英] Converting ASCII strings to UTF-16 before passing them to Windows API functions

查看:108
本文介绍了在将ASCII字符串传递到Windows API函数之前将其转换为UTF-16的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我目前的项目中,我一直在使用宽字符(utf16)。但是,由于我唯一的输入是用户将是一个url,它必须结束ascii反正一个字符串,我想只是切换整个程序ascii。



我的问题是,在将字符串传递给Windows API函数之前,将字符串转换为utf16有什么好处吗?



,如果你在Windows上不使用UTF-16,似乎很多人推荐这样做。

解决方案

在Windows UTF-16是本机编码和所有以 A 结束的API函数只是在 W 那些。 A 函数只是作为与为Windows 9x / ME编写的程序的兼容性,确实,没有新程序应该使用它们(在我看来)。

除非你对数十亿大字符串进行重型处理,否则我怀疑考虑将它们存储在另一个(可能更节省空间)的编码中有什么好处。此外,即使一个URI可以包含Unicode,如果你想到IDN。因此,请不要太担心您的用户会将哪些数据传递给程序。


In my current project I've been using wide chars (utf16). But since my only input from the user is going to be a url, which has to end up ascii anyways, and one other string, I'm thinking about just switching the whole program to ascii.

My question is, is there any benefit to converting the strings to utf16 before I pass them to a Windows API function?

After doing some research online, it seems like a lot of people recommend this if your not working with UTF-16 on windows.

解决方案

The main point is that on Windows UTF-16 is the native encoding and all API functions that end in A are just wrappers around the W ones. The A functions are just carried around as compatibility to programs that were written for Windows 9x/ME and indeed, no new program should ever use them (in my opinion).

Unless you're doing heavy processing of billions of large strings I doubt there is any benefit to thinking about storing them in another (possibly more space-saving) encoding at all. Besides, even an URI can contain Unicode, if you think about IDN. So don't be too sure upfront about what data your users will pass to the program.

这篇关于在将ASCII字符串传递到Windows API函数之前将其转换为UTF-16的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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