首页 > 编程语言 > 详细

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

时间:2020-03-19 09:52:46      阅读:653      评论:0      收藏:0      [点我收藏+]

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

 

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

原文:https://www.cnblogs.com/bigfi/p/12521958.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!