高手帮忙救急了,关于短信接收的一个小问题

yunyue4 2005-11-28 11:18:44
public struct ReceiveMsg
{
public string mobile;
public string senderaddi;
public string recvaddi;
public string ct;
public string sd;
public int flag;
}
private static void getSMSContent(string mobile,string senderaddi, string recvaddi,string ct,string sd,ref int flag)
{
string content = mobile;
int myflag = flag;
}
public delegate void deleSQF(string mobile,string senderaddi, string recvaddi,string ct,string sd,ref int flag);
deleSQF mySmsContent = new deleSQF(getSMSContent);
/// <summary>
/// 接收
/// </summary>
/// <param name="sn"></param>
/// <returns>997 998 999 其它为内容 形式为: 手机号|内容|时间||手机号|内容|时间||</returns>
[DllImport("EUCPComm.dll",EntryPoint="ReceiveSMS")]
public static extern int ReceiveSMS(string sn,deleSQF mySmsContent);

[DllImport("EUCPComm.dll",EntryPoint="ReceiveSMSEx")]
public static extern int ReceiveSMSEx(string sn,deleSQF mySmsContent);

//接收短信
private void Button5_Click(object sender, System.EventArgs e)
{
string sn=System.Configuration.ConfigurationSettings.AppSettings["SN"].ToString().Trim();
ReceiveMsg recMsg=new ReceiveMsg();
deleSQF mySmsContent = new deleSQF(getSMSContent);
int result=ReceiveSMSEx(sn, mySmsContent);
//int result=MMS.ReceiveSMSEx(sn,mySmsContent);
this.Label5.Text="result="+result.ToString();
if(result==1)
{
this.Label4.Text="无短信接收";
}
else if(result==2)
{
this.Label3.Text="收到短信";
if(recMsg.flag==1)
{
this.Label4.Text="手机号码:"+recMsg.mobile+"短信内容:"+recMsg.ct+"接收时间:"+recMsg.sd;
}
else
this.Label4.Text="无内容";
}
else
{
this.Label4.Text="失败";
}

}

我做的一个短信接收的代码,老是接收不到短信,请各位高手帮忙看一下,特别是这几句
ReceiveMsg recMsg=new ReceiveMsg();
deleSQF mySmsContent = new deleSQF(getSMSContent);
int result=ReceiveSMSEx(sn, mySmsContent);
为什么老是接受不到短信的内容呢
是不是有什么问题, 拜托了。
...全文
227 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
RoueDust 2005-12-07
  • 打赏
  • 举报
回复
定义结构时,还需要指定内存分配广方式!
[StructLayout(LayoutKind.Sequential,Pack = 4)]
public struct cmppe_packet
{
public cmppe_head pk_head;
public int result;
public comppe_data_packet pk_data;
}

switch(type)
{
case 0:
this.SMGMainLinkState =SMGLinkState.STATUS_SMG_ERRLINK ;
i_Result = 0;
break;

case (uint)SMS_Command_Type.CMPPE_SUBMIT_RESP://提交短信应答 ;
if( seqSend != seq )
{
i_Result = 4;
break;
}

if( status == 0 )
{ //提交短信成功
SMSMessage( "短信发送成功!" );
i_Result = 0;
break;

}
else
{
SMSMessage(string.Format("短信发送失败:<ICP-TEST>[type={0}][status={1}][seq={2}][result={3}]",type,status,seq,result));
i_Result = this.ReSendMessage() ? 3 : 0 ;
}
break;
代码太多了。说细的QQ:112090935上聊吧!
dasanhai 2005-11-28
  • 打赏
  • 举报
回复
定义结构数据的时候要 使用 UnmanagedType 指定如何将参数或字段封送到非托管代码。
如下:
[StructLayout(LayoutKind.Sequential)]
public class DeliverMsg
{
public uint nIsReport;
public uint nMsgFormat;
public uint nMsgLength;
[ MarshalAs( UnmanagedType.ByValTStr , SizeConst=11 )]
public String sMsgID;
[ MarshalAs( UnmanagedType.ByValTStr , SizeConst=15 )]
public String sRecvTime ;
[ MarshalAs( UnmanagedType.ByValTStr , SizeConst=22 )]
public String sSrcTermID;
[ MarshalAs( UnmanagedType.ByValTStr , SizeConst=22 )]
public String sDestTermID;
[ MarshalAs( UnmanagedType.ByValTStr , SizeConst=253 )]
public String sMsgContent;
}
yunyue4 2005-11-28
  • 打赏
  • 举报
回复
我回复了短信,但是result一直是1
yunyue4 2005-11-28
  • 打赏
  • 举报
回复
ReceiveSMS方法
功能描述:接收部分短消息(不带附加号)
函数声明:
int __stdcall ReceiveSMS(char* sn, MTNRecvContent * rc);
void WINAPI MTNRecvContent(char* mobile,char* senderaddi, char* recvaddi,char* ct,char* sd,int* flag);
参数说明:
mobile:手机号码(当falg=1时有内容)
senderaddi:发送者附加号码(当falg=1时有内容),无此项
recvaddi:接收者附加号码(当falg=1时有内容),无此项
ct:短信内容(当falg=1时有内容)
sd:接收时间(当falg=1时有内容,格式:yyyymmddhhnnss)
flag:1表示有短信,0表示无短信(不用在处理信息了)

参数说明:
参数名称 说明
sn 软件序列号
rc 回调函数指针
返回值:
返回值 说明
101 网络故障
102 其它故障
105 参数指针为空
0 失败
1 成功,没有短消息接收
2 成功,还有短消息接收
-1 未知故障

110,502

社区成员

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

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

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