Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从C++/CLI到C#_C#_String_C++ Cli - Fatal编程技术网

从C++/CLI到C#

从C++/CLI到C#,c#,string,c++-cli,C#,String,C++ Cli,如何将UTF-16字符从C++/CLI函数传递到.NET函数?我在C++/CLI端使用什么类型以及如何转换它 我目前已将C++/CLI函数定义如下: wchar_t GetCurrentTrackID(); // 'wchar_t' is the C++ unicode char equivalent to .NET's 'char'? .NET包装器定义为: System::Char GetCurrentTrackID(); // here, 'char' means UTF-16 ch

如何将UTF-16字符从C++/CLI函数传递到.NET函数?我在C++/CLI端使用什么类型以及如何转换它

我目前已将C++/CLI函数定义如下:

wchar_t GetCurrentTrackID();  // 'wchar_t' is the C++ unicode char equivalent to .NET's 'char'?
.NET包装器定义为:

System::Char GetCurrentTrackID();  // here, 'char' means UTF-16 char
我目前正在使用它来转换它,但在测试它时,我只得到一个空字符。如何正确地将unicode字符代码转换为.NET的
char
等效字符

#pragma managed

return (System::Char)player->GetCurrentTrackID();

它们是直接兼容的。您可以将Char分配给wchar\u t,另一种方法是不使用强制转换,编译器将不会发出任何类型的转换函数调用。对于C++/CLI中的许多简单值类型来说都是如此,比如布尔值对布尔值、SByte对字符、字节对无符号字符、Int16对短值、Int32对int或long、Int64对long、单值对浮点值、双值对双值。加上它们的无符号变体。编译器将它们视为别名,因为它们具有完全相同的二进制表示形式


但不是字符串或数组,它们是具有与本机版本完全不匹配的非平凡实现的类。

据我所知,
System::Char
可以无缝地在
wchar\t
之间转换(至少在Windows上)。你甚至不需要一个明确的演员阵容。