你的程序好像还是有问题! [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=此结构的大小)] }再试试!
string类型的全加上这个, 如:[MarshalAs (UnmanagedType.LPStr)] public string sMsgID;
to 各位!问题还是一样!但是执行到 CMPPDeliver(i,out theDeliverResp);这句是就会报出:“未将对象引用设置到对象的实例。”
[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=此结构的大小)] }再试试!
public string sMsgID;
CMPPDeliver(i,out theDeliverResp);这句是就会报出:“未将对象引用设置到对象的实例。”
你有没有运行InitCMPPAPI(sINIFile)初始化环境?
有些东西你搞半天。不知道什么地方出错:(你类型是否转换对了。可能的话把API原型贴出来看看!!!!
to:panyee(快乐王子)你可以把你的测试程序发给我看看吗?
接受短信(CMPPDeliver)
作用:连接网关,等待接收属于本ICP的短信。
参数:
参数名 数据类型 说明
Ntimeout int 等待时间,单位:秒,0表示永远等待。
PDeliverResp DeliverResp* 保存短信的DeliverResp结构指针。
返回
0=成功
1=失败
以上就是亚信api说明对CMPPDeliver函数的说明。
这里去下在网关模拟器进行测试!希望各位能大力帮助!谢谢
亚信给的结构说明是这样的:
接受短信的返回数据结构(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协议类型