请高手帮忙看看这个API的函数调用有什么问题!(解决和另外一贴一起结分!)

xuyo 2003-08-30 10:15:01
using System.Runtime.InteropServices;
[DllImport("CMPPAPI")]
public static extern int CMPPDeliver(int Ntimeout,out DeliverResp PDeliverResp);
[StructLayout(LayoutKind.Sequential)]
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;
}
const int i=10;//等待时间10秒
DeliverResp theDeliverResp;
theDeliverResp=new DeliverResp();
CMPPDeliver(i,out theDeliverResp);
richTextBox1.Text=theDeliverResp.sMsgContent;\\显示短信内容

以上我是使用亚信提供的CMPP API中的DeliverResp();函数来接收短信,但是执行到
CMPPDeliver(i,out theDeliverResp);这句是就会报出:“未将对象引用设置到对象的实例。”请问问题可能出在什么地方?
...全文
41 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuyo 2003-08-31
  • 打赏
  • 举报
回复
i very need help!
panyee 2003-08-30
  • 打赏
  • 举报
回复
我看了亚信api, 运行CMPPDeliver最多就是个失败, 不会有未实例化的错误

int iend = CMPPDeliver(i,out theDeliverResp); //iend=1,失败


你有没有运行InitCMPPAPI(sINIFile)初始化环境?
xuyo 2003-08-30
  • 打赏
  • 举报
回复
to 各位!问题还是一样!但是执行到
CMPPDeliver(i,out theDeliverResp);这句是就会报出:“未将对象引用设置到对象的实例。”
panyee 2003-08-30
  • 打赏
  • 举报
回复
string类型的全加上这个, 如:

[MarshalAs (UnmanagedType.LPStr)]
public string sMsgID;
zfbt 2003-08-30
  • 打赏
  • 举报
回复
你的程序好像还是有问题!
[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=此结构的大小)]

}

再试试!
cnhgj 2003-08-30
  • 打赏
  • 举报
回复
[DllImport("CMPPAPI.dll")]试试
xuyo 2003-08-30
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2194/2194027.xml?temp=.9401361
也请看看这个贴
dlqycyz 2003-08-30
  • 打赏
  • 举报
回复
关注
成功了能否把处理过程贴出来学习
xuyo 2003-08-30
  • 打赏
  • 举报
回复
i need help!
xuyo 2003-08-30
  • 打赏
  • 举报
回复
我试了!如果是超时的话会以失败返回!也就是返回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协议类型
BigIcicle 2003-08-30
  • 打赏
  • 举报
回复
学习中……
xuyo 2003-08-30
  • 打赏
  • 举报
回复
如果需要可以到:http://skybird.9s9s.com/bbs/topic.asp?topic_id=405
这里去下在网关模拟器进行测试!希望各位能大力帮助!谢谢
xuyo 2003-08-30
  • 打赏
  • 举报
回复
亚信api的CMPPDeliver函数的原形:
接受短信(CMPPDeliver)
作用:连接网关,等待接收属于本ICP的短信。
参数:
参数名 数据类型 说明
Ntimeout int 等待时间,单位:秒,0表示永远等待。
PDeliverResp DeliverResp* 保存短信的DeliverResp结构指针。
返回
0=成功
1=失败
以上就是亚信api说明对CMPPDeliver函数的说明。
xuyo 2003-08-30
  • 打赏
  • 举报
回复
已经初始化了InitCMPPAPI(sINIFile)这个!我运行和网关连通也没有问题!就是使用这个函数的时候就会出这个问题!
to:panyee(快乐王子)你可以把你的测试程序发给我看看吗?我的邮箱liao_j_b@hotmail.com
snewxf 2003-08-30
  • 打赏
  • 举报
回复
C#调用API真烦呀!55555:(
有些东西你搞半天。不知道什么地方出错:(

你类型是否转换对了。可能的话把API原型贴出来看看!!!!

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧