http://expert.csdn.net/Expert/topic/2194/2194027.xml?temp=.9401361
也请看看这个贴

解决方案 »

  1.   

    你的程序好像还是有问题!
    [DllImport("CMPPAPI")]要改为[DllImport("CMPPAPI.dll")]
    你的这个结构
    public struct DeliverResp
    {
    public string sMsgID;
    public int nMsgLevel;
    public string sServiceID;
    public int nMsgFormat;
    public string sSrcTermID;
    public int nIsReply;
    public int nMsgLen;
    public string sMsgContent;
    public string sDestTermID;
    public char cTpPid;
    public char cTpUdhi;
    }
    改成:
    public class DeliverResp
    {
    public string sMsgID;
    public int nMsgLevel;
    public string sServiceID;
    public int nMsgFormat;
    public string sSrcTermID;
    public int nIsReply;
    public int nMsgLen;
    public string sMsgContent;
    public string sDestTermID;
    public char cTpPid;
    public char cTpUdhi;
                               [MarshalAs(UnmanagedType.ByValTStr, SizeConst=此结构的大小)] }再试试!
      

  2.   

    string类型的全加上这个, 如:[MarshalAs (UnmanagedType.LPStr)]
    public string sMsgID;
      

  3.   

    to 各位!问题还是一样!但是执行到
    CMPPDeliver(i,out theDeliverResp);这句是就会报出:“未将对象引用设置到对象的实例。”
      

  4.   

    我看了亚信api, 运行CMPPDeliver最多就是个失败, 不会有未实例化的错误int iend = CMPPDeliver(i,out theDeliverResp); //iend=1,失败 
    你有没有运行InitCMPPAPI(sINIFile)初始化环境?
      

  5.   

    C#调用API真烦呀!55555:(
    有些东西你搞半天。不知道什么地方出错:(你类型是否转换对了。可能的话把API原型贴出来看看!!!!
      

  6.   

    已经初始化了InitCMPPAPI(sINIFile)这个!我运行和网关连通也没有问题!就是使用这个函数的时候就会出这个问题!
    to:panyee(快乐王子)你可以把你的测试程序发给我看看吗?
      

  7.   

    亚信api的CMPPDeliver函数的原形:
    接受短信(CMPPDeliver)
    作用:连接网关,等待接收属于本ICP的短信。
    参数:
    参数名       数据类型        说明
    Ntimeout     int             等待时间,单位:秒,0表示永远等待。
    PDeliverResp DeliverResp*    保存短信的DeliverResp结构指针。
    返回
    0=成功
    1=失败
    以上就是亚信api说明对CMPPDeliver函数的说明。
      

  8.   

    如果需要可以到:http://skybird.9s9s.com/bbs/topic.asp?topic_id=405
    这里去下在网关模拟器进行测试!希望各位能大力帮助!谢谢
      

  9.   

    我试了!如果是超时的话会以失败返回!也就是返回1,但是当我想该函数发送信息的时候就会出现所说的错误!是不是我的结构体定义不对呢??
    亚信给的结构说明是这样的:
    接受短信的返回数据结构(DeliverResp)
    用途:保存CMPPDeliver函数返回的短信内容。
    字段说明:
    字段名              数据类型            说明
    sMsgID              Char(22)            消息标识
    nMsgLevel           Int                 信息级别
    sServiceID          Char(11)            业务类型
    nMsgFormat          Int                 信息格式
    sSrcTermID          Char(22)            源终端MSISDN号码
    nIsReply            Int                 是否为应答信息
    nMsgLen             Int                 消息长度
    sMsgContent         Char(16)            消息内容
    sDestTermID         Char(21)            SP的接入代码
    cTpPid              Char                GSM协议类型
    cTpUdhi             Char                GSM协议类型