初始化 monorepo: Go后端(7微服务) + Unity客户端(9模块) + 启动器 HTML5原型: Three.js 3D体素世界, Perlin噪声地形, 原版材质, 22种方块 Minecraft创造模式背包: 双栏布局, 拖拽移动物品, 方向性元件引脚 AI助搭策划文档 + 客户端/服务端骨架 + Docker Compose + CI
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace PCL.Core.Utils.WinRT;
|
||||
|
||||
public class HStringHelper
|
||||
{
|
||||
public static unsafe HString ToHString(string? value)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
return new HString(IntPtr.Zero);
|
||||
}
|
||||
|
||||
IntPtr handle;
|
||||
fixed (char* lpValue = value)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(
|
||||
WinRTInterop.WindowsCreateString((ushort*)lpValue, value.Length, &handle));
|
||||
}
|
||||
|
||||
return new HString(handle);
|
||||
}
|
||||
|
||||
public static unsafe string ToManagedString(HString value)
|
||||
{
|
||||
if (value == IntPtr.Zero)
|
||||
return "";
|
||||
uint length;
|
||||
var buffer = WinRTInterop.WindowsGetStringRawBuffer(value, &length);
|
||||
return length != 0 ? new string(buffer, 0, (int)length) : string.Empty;
|
||||
}
|
||||
|
||||
public static void DeleteHString(HString value)
|
||||
{
|
||||
if (!value.IsNull)
|
||||
WinRTInterop.WindowsDeleteString(value);
|
||||
}
|
||||
|
||||
public static unsafe void WithReference(
|
||||
ReadOnlySpan<char> value,
|
||||
Action<HString> action)
|
||||
{
|
||||
fixed (char* p = value)
|
||||
{
|
||||
WinRTInterop.HStringHeader header;
|
||||
IntPtr hstring;
|
||||
|
||||
Marshal.ThrowExceptionForHR(
|
||||
WinRTInterop.WindowsCreateStringReference(
|
||||
(ushort*)p,
|
||||
value.Length,
|
||||
(IntPtr*)&header,
|
||||
&hstring));
|
||||
|
||||
action((HString)hstring);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user