用C#调用C++DLL时的字符串指针参数传递问题
下面是C++中的函数原型和调用方法
CMPP_API dpl_status_t cmpp_connect_to_ismg(char *host,dpl_port_t port,conn_desc *conn);
stat = cmpp_connect_to_ismg("211.130.24.51",7800,&conn);//建立与ISMG服务器的连接
用C#怎么调用呢?
示例:
[ DllImport( "api.dll", CharSet=CharSet.Ansi)] // EntryPoint="cmpp_connect_to_ismg",
调用
string ipstr="211.138.24.51";
stat = esp.cmpp_connect_to_ismg(ipstr,7890,ref conn);//建立与ISMG服务器的连接
CMPP_API dpl_status_t cmpp_connect_to_ismg(char *host,dpl_port_t port,conn_desc *conn);
stat = cmpp_connect_to_ismg("211.130.24.51",7800,&conn);//建立与ISMG服务器的连接
用C#怎么调用呢?
示例:
[ DllImport( "api.dll", CharSet=CharSet.Ansi)] // EntryPoint="cmpp_connect_to_ismg",
public static extern int cmpp_connect_to_ismg( ref string host,short port,[MarshalAs(UnmanagedType.LPStruct)] ref conn_desc conn);
//@@无符号short//
调用
string ipstr="211.138.24.51";
stat = esp.cmpp_connect_to_ismg(ipstr,7890,ref conn);//建立与ISMG服务器的连接
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步