c# 调用 c++的 dll 中关于 char*传入传出参数


c++的dll接口原型为:int CheckSN(const char* InfoList, char* msg);

c#调用转换为:

[DllImport("sncplusInterface.dll", EntryPoint = "CheckSN", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int CheckSN(string InfoList, StringBuilder msg);

调用为:

StringBuilder chOutMsg = new StringBuilder(1024);

CheckSN(chData, chOutMsg/*ref chOutMsg*/);

string str = chOutMsg.ToString();

用ref 或 out关键字会crash

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM