[英]Convert wchar_t to CFStringref
I have a wchar_t *
that I need to use on a function that needs a CFStringref
我有一个wchar_t *
,我需要在需要CFStringref
的函数上使用
I tried using CFStringCreateWithCharacters
but I'm not getting anywhere with it. 我尝试使用CFStringCreateWithCharacters
但我没有随处CFStringCreateWithCharacters
。
So, if I have: 所以,如果我有:
wchar_t * widecharvar = L"some value";
CFStringRef stringref;
How do I convert and copy widecharvar
to stringref
? 如何将widecharvar
转换并复制到stringref
? This value will be used in SecRequirementCreateWithString()
该值将在SecRequirementCreateWithString()
Thanks 谢谢
I'm doing this off the top of my head and memory; 我正在做我的头脑和记忆; if it has trouble, comment and I'll actually test it. 如果它有问题,评论,我会实际测试它。
// Check our byte order. Assuming we made the string as in your example
CFStringEncoding encoding = (CFByteOrderLittleEndian == CFByteOrderGetCurrent()) ?
kCFStringEncodingUTF32LE : kCFStringEncodingUTF32BE;
int widecharvarLen = wcslen(widecharvar);
CFStringRef string = CFStringCreateWithBytes(NULL,
widecharvar,
(widecharvarLen * sizeof(wchar_t)),
encoding,
false);
That last false
means that string does not include a BOM (Byte Order Mark), which is the kind of string I assume you're dealing with. 最后一个false
意味着字符串不包含BOM(字节顺序标记),这是我假设您正在处理的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.