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

来源:互联网 发布:数控车床锥度编程实例 编辑:程序博客网 时间:2024/04/25 12:18

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);

0 0
原创粉丝点击