CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

C#调用CMPP的东软Api(DLl)出问题,请C#高手帮助!分不够可以再加!

楼主sgp1201(无为)2005-04-03 15:46:25 在 .NET技术 / C# 提问

cmpp_connect_to_ismg("127.0.0.1",   7890,   cns);   这个已经成功了  
  cmppe_login   cpl   =   new   cmppe_login();这个登录有问题!  
  未处理的“System.NullReferenceException”类型的异常出现在   WindowsApplication1.exe   中。  
   
  是不是我定义的结构要传参数,这个结构是根据标准C的头文件翻译过来的!  
   
   
  其他信息:   未将对象引用设置到对象的实例。  
   
  以下是完整的代码:  
  using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
  using   System.Runtime.InteropServices;  
  using   System.Net.Sockets;  
   
  namespace   WindowsApplication1  
  {  
  #region   CMPP结构定义  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   cmppe_head  
  {  
  public   uint   pk_len;  
  public   uint   pk_cmd;  
  public   uint   pk_stat;  
  public   uint   pk_seq;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   cmppe_login  
  {  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   6)]    
  public   string   icp_id;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   icp_auth;  
  public   byte icp_bind_type;  
  public   byte if_version;  
  public   uint icp_timestamp;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   cmppe_login_resp  
  {  
  public   byte if_version;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   ismg_auth;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   cmppe_submit  
  {  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   6)]    
  public   string   icp_id;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   svc_type;  
  public   byte fee_type;  
  public   uint info_fee;  
  public   byte proto_id;  
  public   byte msg_mode;  
  public   byte priority;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   validate;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   schedule;  
  public   byte fee_utype;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   fee_user;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   src_addr;  
  public   byte du_count;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   dst_addr;  
  public   byte data_coding;  
  public   byte sm_len;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   short_msg;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct cmppe_us_user  
  {  
  public   byte index;  
  public   byte stat;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   cmppe_submit_resp  
  {  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   msg_id;  
  public   byte us_count;  
  public   cmppe_us_user   us_user;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   cmppe_deliver_rpt  
  {  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   msg_id;  
  public   byte final_status;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   submit_date;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   final_date;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public     struct   cmppe_mo_msgcontent  
  {  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   160)]  
  public   string short_msg;  
  public   cmppe_deliver_rpt   sm_rpt;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   cmppe_deliver  
  {  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   src_addr;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   dst_addr;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   svc_type;  
  public   byte proto_id;  
  public   byte status_rpt;  
  public   byte priority;  
  public   byte data_coding;  
  public   byte sm_len;  
  public   cmppe_mo_msgcontent   pk_sm;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   cmppe_cancel  
  {  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   msg_id;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   icp_trans  
  {  
  public   Socket   socket;  
  public   uint   sequence;  
  public   uint   icp_seq;  
  public   byte mode;  
  public   byte status;  
  public   byte stat;  
  public   byte version;  
  [MarshalAs(UnmanagedType.ByValTStr,   SizeConst   =   16)]    
  public   string   icp_id;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   icp_data_packet  
  {  
  public   cmppe_login   login_body;  
  public   cmppe_submit   submit_body;  
  public   cmppe_cancel   cancel_body;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   icp_packet  
  {  
  public   uint   pk_cmd;  
  public   uint   pk_seq;  
  public   uint   pk_stat;  
  public   icp_data_packet   pk_data;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   comppe_data_packet  
  {  
  public   cmppe_deliver pk_deliver;  
  public   cmppe_login_resp pk_login_resp;  
  public   cmppe_submit_resp pk_submit_resp;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   cmppe_packet  
  {  
  public   cmppe_head pk_head;  
  public   uint   result;  
  public   comppe_data_packet   pk_data;  
  }  
   
  [StructLayout(LayoutKind.Sequential,   Pack   =   1)]  
  public   struct   conn_desc  
  {  
  public   Socket   sock;  
  public   long   seq;  
  public   int   status;  
  public   char   act_flag;  
  }  
   
  #endregion  
   
  public   delegate   void   On_conn_desc();  
  public   delegate   void   On_cmppe_login();  
   
  ///   <summary>  
  ///   Form1   的摘要说明。  
  ///   </summary>  
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
  private   System.Windows.Forms.Button   button1;  
  private   System.Windows.Forms.TextBox   textBox1;  
   
  ///   <summary>  
  ///   必需的设计器变量。  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
   
  public   Form1()  
  {  
  //  
  //   Windows   窗体设计器支持所必需的  
  //  
  InitializeComponent();  
   
  //  
  //   TODO:   在   InitializeComponent   调用后添加任何构造函数代码  
  //  
  }  
   
  ///   <summary>  
  ///   清理所有正在使用的资源。  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  if(   disposing   )  
  {  
  if   (components   !=   null)    
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(   disposing   );  
  }  
   
   
   
   
  问题点数:100、回复次数:10Top

1 楼sgp1201(无为)回复于 2005-04-03 15:46:42 得分 0

接上页  
   
  #region   Windows   窗体设计器生成的代码  
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  this.button1   =   new   System.Windows.Forms.Button();  
  this.textBox1   =   new   System.Windows.Forms.TextBox();  
  this.SuspendLayout();  
  //    
  //   button1  
  //    
  this.button1.Location   =   new   System.Drawing.Point(104,   224);  
  this.button1.Name   =   "button1";  
  this.button1.TabIndex   =   0;  
  this.button1.Text   =   "button1";  
  this.button1.Click   +=   new   System.EventHandler(this.button1_Click);  
  //    
  //   textBox1  
  //    
  this.textBox1.Location   =   new   System.Drawing.Point(0,   0);  
  this.textBox1.Multiline   =   true;  
  this.textBox1.Name   =   "textBox1";  
  this.textBox1.Size   =   new   System.Drawing.Size(296,   208);  
  this.textBox1.TabIndex   =   1;  
  this.textBox1.Text   =   "textBox1";  
  //    
  //   Form1  
  //    
  this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);  
  this.ClientSize   =   new   System.Drawing.Size(292,   273);  
  this.Controls.Add(this.textBox1);  
  this.Controls.Add(this.button1);  
  this.Name   =   "Form1";  
  this.Text   =   "Form1";  
  this.Load   +=   new   System.EventHandler(this.Form1_Load);  
  this.ResumeLayout(false);  
   
  }  
  #endregion  
   
  ///   <summary>  
  ///   应用程序的主入口点。  
  ///   </summary>  
  [STAThread]  
  static   void   Main()    
  {  
  Application.Run(new   Form1());  
  }  
   
   
  #region   API函数声明  
   
  public   static   void   Onconn_desc()  
  {  
  }  
   
  public   static   void   Oncmppe_login()  
  {  
  }  
   
   
  // [DllImport("api.dll")]  
  // public   static   extern   int   cmpp_connect_to_ismg(string   host,   int   port,   On_conn_desc   cns);  
  //  
  // [DllImport("api.dll")]  
  // public   static   extern   int   cmpp_login(On_conn_desc   cns,On_cmppe_login   cpl);  
  //  
   
  //标准C函数原型  
  /*cmpp_connect_to_ismg  
  功能描述  
  建立与ISMG服务器的连接  
  函数原型  
  dpl_status_t   cmpp_connect_to_ismg(char   *host,dpl_port_t   port,conn_desc   *conn);  
  返回值  
  DPL_SUCCESS:成功与服务器建立连接  
  DPL_EINVALSOCK:创建连接套接字失败  
  DPL_EINVAL:非法服务器地址  
  DPL_HOST_UNREACHABLE:连接服务器失败  
        参数  
          host:服务器的IP地址  
        port:服务器的端口号  
        conn:输出参数,用于传出对ISMG的连接描述  
  */  
  [DllImport("api.dll")]  
  public   static   extern   int   cmpp_connect_to_ismg(string   host,   int   port,   On_conn_desc   cns);  
   
  //标准C函数原型  
  /*   cmpp_login  
  功能描述  
  发送登录请求到远程ISMG服务器  
  函数原型  
  dpl_status_t   cmpp_login(conn_desc   *conn,cmppe_login   *cl)  
  返回值  
  DPL_SUCCESS:发送请求成功  
  其他 网络原因造成登录失败,返回错误码  
        参数  
        conn:与ISMG的连接描述   cl:登录请求包  
  */  
  [DllImport("api.dll")]  
  public   static   extern   int   cmpp_login(On_conn_desc   cns,cmppe_login   cpl);  
   
  #endregion  
   
  private   void   button1_Click(object   sender,   System.EventArgs   e)  
  {  
  On_conn_desc   cns   =   new   On_conn_desc(Onconn_desc);  
  // On_cmppe_login   cpl   =   new   On_cmppe_login(Oncmppe_login);  
   
  int   nRetCode;  
  nRetCode   =   cmpp_connect_to_ismg("127.0.0.1",   7890,   cns);    
  MessageBox.Show(nRetCode.ToString());  
   
  cmppe_login   cpl   =   new   cmppe_login();  
  cpl.icp_id   =   "954321";  
  // cpl.icp_auth   =   "954321";  
  // cpl.icp_bind_type   =   2;  
  // cpl.if_version   =   0x12;  
  // cpl.icp_timestamp   =   (uint)DateTime.Now.ToFileTimeUtc();  
   
  nRetCode   =   cmpp_login(cns,   cpl);  
  }  
   
  private   void   Form1_Load(object   sender,   System.EventArgs   e)  
  {  
   
  }  
  }  
  }  
  Top

2 楼qing_zhou(轻舟)回复于 2005-04-03 16:16:19 得分 0

好长啊,先顶住。Top

3 楼fans869(fans869@china.com)回复于 2005-04-03 18:07:53 得分 20

晕Top

4 楼nadoo()回复于 2005-04-04 21:42:28 得分 20

给你顶住...     我毕业去东软工作.Top

5 楼sgp1201(无为)回复于 2005-04-05 09:02:44 得分 0

自己顶!Top

6 楼3gold(新丁)回复于 2005-04-05 09:06:42 得分 20

这么长,怎么看啊?Top

7 楼sgp1201(无为)回复于 2005-04-08 18:12:53 得分 0

自己解决了!Top

8 楼sgp1201(无为)回复于 2005-04-08 18:16:48 得分 0

谢谢各位支持,等有人提点有意义的见解就结!Top

9 楼Flashcom(虫虫)回复于 2005-04-08 18:52:31 得分 40

C#调用C++的的API总觉得不爽,所以自己用C#写了一个CMPP3的API,基本的的登陆、提交短信接收短信或状态报告等都完成了,在压力的测试下也完成了,也在华为的网关测试过了!但总觉得代码还不够完美,所以还在进步完善中。。不过最近都没有时间在搞它了!Top

10 楼hoen(coolpocket)回复于 2005-06-29 16:03:23 得分 0

呵呵今天刚弄完了Top

相关问题

  • C# API
  • 调c的dll!
  • C# Dll 问题
  • 关于C++ 与 DLL
  • Windows API和C
  • 求:C#下API
  • C#怎么使用c写的dll啊?
  • c++如何调用c写的dll??
  • 向高手學習!C# 訪問 DLL(C++)
  • c/c++的dll编程问题,??

关键词

  • c#
  • 函数
  • 服务器
  • 代码
  • 原型
  • 连接
  • 结构
  • cmpp
  • cmppe
  • ismg

得分解答快速导航

  • 帖主:sgp1201
  • fans869
  • nadoo
  • 3gold
  • Flashcom

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo