ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用C#调用C++DLL时的字符串指针参数传递问题

用C#调用C++DLL时的字符串指针参数传递问题

原创 Linux操作系统 作者:iDotNetSpace 时间:2008-09-05 16:20:36 0 删除 编辑
下面是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",  

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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-442047/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    2376
  • 访问量
    5766197