.net 生成非托管代码

最近在一个老外的程序中看到一段代码,其中使用了System.Runtime.InteropServices.MarshalAs方法进行托管代码与非托管代码之间封装数据,感觉很新颖。特意记录下来,供大家参考

[DllExport("ExpTest", CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static string ExpTest([MarshalAs(UnmanagedType.LPWStr)] ref string sText, out int length)
{
    MessageBox.Show(sText, "ExpTest");
    length = sText.Length;
    return sText;
}
原文地址:https://www.cnblogs.com/MuNet/p/11492155.html