用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服务器的连接