首页 > 代码库 > C#调用C接口字符参数编码的问题解决方法

C#调用C接口字符参数编码的问题解决方法

1、传入单字节ANSI字符

[DllImport("hostIO", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]

    public static extern int initHost([MarshalAs(UnmanagedType.LPStr)] string host);


2、传入双字节Unicode字符

[DllImport("hostIO", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    public static extern int initHost([MarshalAs(UnmanagedType.LPWStr)] string host);

C#调用C接口字符参数编码的问题解决方法