📄 delphi»
字号:
SMS客户程序:指需要调用SMSCLIENT.DLL中的函数来收发短消息的程序。
SMS服务程序: 指提供短消息服务的程序。
SMS客户程序通过引入SMSCLIENT.DLL 中的4个函数,来获得短消息收发能力
function InitConnect(hostname:pchar):Integer; cdecl external 'SMSCLIENT.DLL';
功能:初始化SMS客户程序与SMS服务程序的连接
参数说明:hostname--指运行SMS服务程序的计算机的网络标识
返回:-1--失败 0--成功
function SendMsg(SCA:pchar;DA:pchar;UD:pchar):Integer; cdecl external 'SMSCLIENT.DLL';
功能:发送一条短消息(实际上是提交一条消息给SMS服务程序,由SMS服务程序发出去)
参数说明:SCA--短消息中心号码(如成都移动就是:"13800280500")
DA--接收方手机号码(如"13980711226")
UD--消息内容(如"你好!");
返回:-1:提交给SMS服务程序失败
0:提交给SMS服务程序成功
function QueryMsg:Integer; cdecl external 'SMSCLIENT.DLL';
功能:查询SMS服务程序
参数说明:无
返回:-1--查询失败,SMS服务程序无响应。
0--查询成功,SMS服务程序端没有收到的消息。
N(1,2,...)--查询成功,SMS服务程序有N条收到的消息。
function ReadMsg:pchar; cdecl external 'SMSCLIENT.DLL';
功能:读取一条消息
参数说明:无
返回:""--读取失败,SMS服务程序无响应
"EMPTY"--读取成功,但SMS服务程序内没有收到的消息。
"OA:..."--读取成功,而且SMS服务程序有收到的消息。
具体格式
"OA:发送方号码 TIME:接收到该消息的时间 UD:消息内容"
在Delphi中的使用示例:
首先在欲调用DLL函数的unit中声明函数:
var
function InitConnect(hostname:pchar):Integer; cdecl external 'SMSCLIENT.DLL';
function QueryMsg:Integer; cdecl external 'SMSCLIENT.DLL';
function SendMsg(SCA:pchar;DA:pchar;UD:pchar):Integer; cdecl external 'SMSCLIENT.DLL';
function ReadMsg:pchar; cdecl external 'SMSCLIENT.DLL';
在调用DLL处加入如下语句进行DLL装载:
var r,i:integer;
s:string;
//在程序启动后,应当进行初始化连接操作:
r:=InitConnect('xtpad'); //xtpad是运行sms服务程序的计算机网络名称,这里是举例。
if r=-1 then ShowMessage('初始化连接失败:SMS服务器没有响应');
//需要发送消息时:
i:=SendMsg(pchar('13800280500'),pchar(edit1.text),pchar(memo1.text));
if i=-1 then showmessage('failed!')
else showmessage('success');
//查询SMS服务程序中有几条未读取的消息:
i:=QueryMsg;
if i=-1 then
begin
statusbar1.Panels[0].text:='SMSServer 异常或没有启动';
end;
if i=0 then
begin
statusbar1.Panels[0].text:='SMSServer正常,没有收到的消息';
end;
if i>0 then
begin
statusbar1.Panels[0].text:='SMSServer 正常,还有'+inttostr(i)+'条收到的信息';
end;
//读取一条消息
try
s:=ReadMsg;
Memo2.Lines.Add('收到:'+s);
except
end;
.....
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -