调用华为SMEIDll发送短信,遇到下面的问题,请赐教,我是什么地方写错了 ( 积分: 100 )

  • 主题发起人 主题发起人 lixiaohui
  • 开始时间 开始时间
L

lixiaohui

Unregistered / Unconfirmed
GUEST, unregistred user!
type
PLongword = ^Longword;
PInteger = ^Integer;
PByte = ^Byte;
function BdSendMsg(phone,msg,OAddr:string):integer;

function SubmitAExEx(OrgTON:BYTE;OrgNPI:BYTE;OrgAddr:Pchar;
DestTON:BYTE;DestNPI:BYTE;DestAddr:Pchar;
PRI:BYTE;RD:BYTE;RP:BYTE;
SRR:BYTE;MR:BYTE;DCS:BYTE;
PID:BYTE;Schedule:Pchar;Expire:Pchar;
Default_ID:longword;UDHI:BYTE;UDLen:longword;
UserData:Pchar;ServiceSubType:pchar;
byMsgID:PByte;byPKTotal:BYTE;
byPKNumber:BYTE;byMsglevel:BYTE;
byFeeUserType:BYTE;sSPID:Pchar;sFeeType:Pchar;
sFeeAddr:Pchar;sFeeCode:Pchar;byUserNum:BYTE;
sDestAddrs:Pchar;SM_ID:PLongword;FCS:PBYTE
):integer;stdcall;external 'SMEIDll.dll' name 'SubmitAExEx';


function BdSendMsg(phone,msg,OAddr:string):integer;
var
iRet :integer;
OrgTON:BYTE;OrgNPI:BYTE;
OrgAddr:string;
DestTON:BYTE;DestNPI:BYTE;
DestAddr:string;
PRI:BYTE;RD:BYTE;RP:BYTE;
SRR:BYTE;MR:BYTE;DCS:BYTE;
PID:BYTE;
Default_ID:longword;
UDHI:BYTE;
UDLen:longword;
Schedule,Expire:string;
byMsgID:PBYTE;
UserData,ServiceSubType:string;
byPKTotal:BYTE;
byPKNumber:BYTE;byMsglevel:BYTE;
byFeeUserType:BYTE;
byUserNum:BYTE;
sSPID,sFeeType,sFeeAddr,sFeeCode,sDestAddrs:string;
SM_ID:Longword;
FCS :Byte;
begin

try

OrgTON:=1; //源地址号码类型
OrgNPI:=1; //源地址编码方案
OrgAddr:=OAddr;
DestTON:=2; //目标地址号码类型
DestNPI:=1; //目标地址编码方案
DestAddr:='';
PRI:=0; //SM优先级
SRR:=1; //状态报告
DCS:=8; //数据编码方案
PID:=0;
default_id:=0; //缺省短消息的信息码,缺省为0。
UDHI:=0; //用于长短消息,表示UserData是否是结构
UserData:=msg;
UDLen:=length(msg); //用户信息,短消息正文
Schedule:='';
Expire:='';
ServiceSubType:='bdmc';
byPKTotal:=1; //相同Msg_id的消息总条数,从1开始
byPKNumber:=1; //相同Msg_id的消息序号,从1开始
byMsgLevel:=9; //信息级别,缺省为0。
byFeeUserType:=0; //计费用户类型字段:
sSPID:='403113';
sFeeType:='01';
sFeeCode:='000010';
byUserNum:=1; //接收消息的用户数量
sFeeAddr:='';
sDestAddrs:=phone;
GetMem(byMsgID,22);
ZeroMemory(byMsgID,22);
try
iRet:= SubmitAExEx(OrgTON,OrgNPI,pchar(OrgAddr),DestTON,DestNPI,pchar(DestAddr),PRI,0,0,
SRR,0,DCS,PID,pchar(Schedule),pchar(Expire),default_id,UDHI,UDLen,pchar(UserData),
pchar(ServiceSubType),byMsgID,byPKTotal,
byPKNumber,byMsgLevel,byFeeUserType,
pchar(sSPID),pchar(sFeeType),pchar(sFeeAddr),pchar(sFeeCode),
byUserNum,pchar(sDestAddrs),@SM_ID,@FCS);
//frmMain.memlog.Lines.Add('ACK应答消息的MsgID:'+inttostr(byMsgID^)+'短消息ID:'+inttostr(SM_ID^)+'SC端失败原因:'+inttostr(FCS^))
finally
if byMsgID<>nil then
FreeMem(byMsgID);
end;
result:=iRet;
except
on e:exception do begin
frmMain.memlog.Lines.Add('异常发现:'+e.Message);
result:=600; //自定义异常错误
raise;
exit;
end;
end;
end;

虽然可以正常发送短信,但偶尔捕获到异常:
Access violation at address 10027DD6 in module 'SMEIDll.dll'. Read of address 011B4000
请各位大侠赐教,是什么地方出了问题?
 
华为api函数如下:

int WINAPI SubmitAExEx(unsigned char OrgTON, unsigned char OrgNPI, LPCTSTR OrgAddr,unsigned char DestTON, unsigned char DestNPI, LPCTSTR DestAddr, unsigned char PRI, unsigned char RD, unsigned char RP, unsigned char SRR, unsigned char MR, unsigned char DCS, unsigned char PID, LPCTSTR Schedule, LPCTSTR Expire, unsigned long Default_ID, unsigned char UDHI, unsigned long UDLen,LPCTSTR UserData, LPCTSTR ServiceSubType, unsigned char* byMsgID, unsigned char byPKTotal, unsigned char byPKNumber, unsigned char byMsglevel,
unsigned char byFeeUserType, LPCTSTR sSPID, LPCTSTR sFeeType, LPCTSTR sFeeAddr, LPCTSTR sFeeCode,unsigned char byUserNum, LPCTSTR sDestAddrs,unsigned long* SM_ID, unsigned char* FCS)
注:SubmitAExEx主要适用于CMPP协议(移动)。
 
经验而已,一般出现AV错误,可能是有些传出的指针没有分配缓冲区,或者不够长,看看API的自带帮助文档,还有一个情况,就是API函数接口定义的问题,WINAPI在VC里面应该是对应Delphi的cdecl修饰,BCB的WINAPI对应Delphi是StdCall修饰,如果你声明的不正确,当你调用函数执行结束后会出现AV错误。
 
可不是每次都会出错是呀,数据量比较多的时候才会偶尔出现这个错误呀
 
把 DLL 给我一份吧
 
实际上如果函数头声明错的话,不会每次都出错,但是会有莫名其妙的错误.你可以试一下,如果在BdSendMsg函数单步执行,查看各个变量的变化,如果异常的话,可能就是函数头声明的有问题
 
to-QSmile 你的邮箱是多少,如何发给你
to-一只没有缺点的狼,我试过单步跟踪,没发现有问题呀
 
后退
顶部