雨
雨季飘零
Unregistered / Unconfirmed
GUEST, unregistred user!
由实达厂家提供的DLL,我在DELPHI中调用,但是发送中文短消息收不到,只能发送英文的,以下是主窗体的代码,谁能帮我看看,谢谢了,主要看我注释的那一部门<br>unit main;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, ExtCtrls, ComCtrls, StdCtrls, Buttons;<br><br>type<br> TsmsMain = class(TForm)<br> Panel1: TPanel;<br> Memo1: TMemo;<br> StatusBar1: TStatusBar;<br> Label1: TLabel;<br> eCom: TEdit;<br> Label2: TLabel;<br> eRate: TEdit;<br> label3: TLabel;<br> eCenter: TEdit;<br> eText: TEdit;<br> Label4: TLabel;<br> Label5: TLabel;<br> ePhone: TEdit;<br> BitBtn1: TBitBtn;<br> BitBtn2: TBitBtn;<br> BitBtn3: TBitBtn;<br> Button1: TButton;<br> BitBtn4: TBitBtn;<br> BitBtn5: TBitBtn;<br> BitBtn6: TBitBtn;<br> procedure FormShow(Sender: TObject);<br> procedure BitBtn1Click(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure BitBtn3Click(Sender: TObject);<br> procedure BitBtn2Click(Sender: TObject);<br> procedure OnFormClose(Sender: TObject; var Action: TCloseAction);<br> procedure BitBtn4Click(Sender: TObject);<br> procedure BitBtn5Click(Sender: TObject);<br> procedure BitBtn6Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br> {设置通讯口:入口: szPort: 通讯端口名: "COM1","COM2","COM3"...<br> szRate: 通讯速率,通常取"57600"<br> 返回: SUCC: 成功<br> FAIL: 失败<br> 说明:在使用动态链接库对MODEM进行操作之前,请先调用该函数打开PC机的串口 }<br> function WM_init(szPort,szRate : pChar):integer;stdcall;external 'wmdll.dll';<br><br> {初始化与MODEM的通信:返回: SUCC: 成功<br> -1/-2/-3: 失败<br> -7 未打开串口<br> 说明:在串口设置成功后,请先调用该函数初始化MODEM}<br> function WmCommInit:short;stdcall;external 'wmdll.dll';<br><br> {设置信息中心:入口: szSmsCen: 信息中心号码: "+8613800591500"<br> 返回: SUCC: 成功<br> FAIL: 失败<br> -7 未打开串口<br> 说明:与手机的使用相同,在第一次使用MODEM进行短信通信功能之前,必须至少设置一次信息中心号码。 }<br> function SmsInit(szSmsCenChar):integer;stdcall;external 'wmdll.dll';<br><br><br> function Dial(szSmsCenChar):smallint;stdcall;external 'wmdll.dll';<br><br><br> {获得无线MODEM最多允许存储的信息数:入口: 无<br> 返回: -2: 与MODEM通信失败<br> -1: 解码错误<br> -7 未打开串口<br> 其他整数: 无线MODEM最多允许存储的信息数}<br> function Sms_Amount:integer;stdcall;external 'wmdll.dll';<br><br> {发送短消息:入口: szSmsBuf:存储发送的信息内容 ,最多允许发送70个中文。<br> uiSmsLen: 存储要发送的信息长度<br> phone: <br> 存储要发送的电话号码,格式为86138*******,即前面必须以86起始<br> 返回: SUCC: 成功<br> FAIL: 失败<br> -7 未打开串口}<br> function SmsSend(szSmsBufchar;uiSmsLen:integer; phonechar):integer;stdcall;external 'wmdll.dll';<br><br> {读取存储序号为index的信息:入口:<br> index: 存储序号,(取值范围:1~最多存储的信息数,从Sms_Amount函数返回) szSmsBuf: 由用户定义,用来存储解码后的信息内容。缓存区大小不要小于140字节<br> iLenStr: 由用户定义,用来存储返回的信息内容长度<br> szSmsPhone: 由用户定义,用来存储该信息发送方的电话号码。<br> szSmsTime: 由用户定义,用来存储该信息发送的时间。格式如030305172536,表示03年03月05日17时25分36秒<br> szSmsCen: 由用户定义,用来存储该信息发送的信息中心号码。<br> 返回:<br> SUCC: 成功,并将解码后的信息内容、该信息发送方电话号码、信息中心号码、发送时间均存在相应的缓存区内。即上面定义的szSmsBuf、szSmsPhone、szSmsTime、szSmsCen<br> -1: 短消息读取失败<br> -2:该序号无对应信息<br> 0: 存在无法正确解码的编码,并将已经解好的部分存储在相应缓存区内,如同SUCC。<br> -5:由于信息长度错误,导致发送信息失败。<br> -7 未打开串口 }<br> function SmsSendText(szSmsBufchar;uiSmsLen:integer; phonechar):integer;stdcall;external 'wmdll.dll';<br> {<br> 以text方式发送短消息:入口:<br> 返回:<br> SUCC: 成功<br> FAIL: 失败<br> }<br><br> function Sms_Read_VC(index:integer;szSmsBufchar;var iLenStr:integer;szSmsPhone,szSmsTime,szSmsCenchar):integer;stdcall;external 'wmdll.dll';<br> function ReadNextSms(szSmsBufchar;var iLenStr:integer;szSmsPhone,szSmsTime,szSmsCenchar):integer;stdcall;external 'wmdll.dll';<br><br> {删除短信息:入口: index ,将要删除的短信的序号<br> (取值范围:1~最多存储的信息数,从Sms_Amount函数返回)<br> 返回: SUCC: 成功<br> FAIL: 失败<br> -7 未打开串口}<br> function Sms_Del(index:integer):integer;stdcall;external 'wmdll.dll';<br><br> {关闭打开了的串口:返回: SUCC: 成功<br> 2 成功,与SUCC含义不同之处在于,它表示串口未用WM_init成功初始化过。<br> FAIL: 失败<br> 说明:<br> 一旦用WM_init函数设置通信串口之后,请调用该函数释放线程,否则会一直占用系统资源 }<br> function port_close:integer;stdcall;external 'wmdll.dll';<br><br>var<br> smsMain: TsmsMain;<br> iWm_init,iWmCommInit,ismsInit,ismsSend,iRead : integer;<br> sWmCommInit : short;<br> iIndex : integer;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TsmsMain.FormShow(Sender: TObject);<br>begin<br> memo1.Clear ;<br>end;<br><br>procedure TsmsMain.BitBtn1Click(Sender: TObject);<br>var<br> sePhone,sCenter,sText : string;<br> pCenter : array[0..20] of char;<br> pPhone : array[0..20] of char;<br> pText : array[0..140] of char;<br> i,iLen : integer;<br>begin<br> if eText.Text = '' then begin<br> showmessage('发送短信内容不能为空!');<br> if eText.CanFocus then eText.SetFocus ;<br> exit;<br> end;<br> if ePhone.Text = '' then begin<br> showmessage('对方电话不能为空!');<br> if ePhone.CanFocus then ePhone.SetFocus ;<br> exit;<br> end;<br> {设置通讯口}<br> iWm_init := Wm_init(pchar( trim(eCom.Text) ),pchar( trim(eRate.Text) ));<br> if iWm_init = 0 then begin<br> memo1.Lines.Add('设置通讯口失败!');<br> exit;<br> end;<br> {初始化MORDEM}<br> sWmCommInit := WmCommInit;<br> if sWmCommInit <> 1 then begin<br> Memo1.Lines.Add('初始化MORDEM失败!'+inttostr(iWmCommInit));<br> port_close;<br> exit;<br> end;<br> {设置短信中心号码}<br> sCenter := trim( eCenter.Text );<br> for i := 1 to length(eCenter.Text) do begin<br> pCenter[i-1] := sCenter;<br> end;<br> pCenter:=#0;<br> <br> ismsInit := smsInit( pCenter );<br> if ismsInit <> 1 then begin<br> Memo1.Lines.Add('设置短信中心号码失败(1)!'+inttostr(ismsInit));<br> port_close;<br> exit;<br> end; <br> {发送短信}<br> sePhone := '86'+trim( trim( ePhone.Text ) );<br> for i := 1 to length( sePhone ) do begin<br> pPhone[i-1] := sePhone;<br> end;<br> pPhone:= #0;<br> <br> iLen := length( eText.Text );<br> sText := trim( eText.Text );<br> fillchar(ptext,sizeof(pText),ord(' '));<br> for i := 1 to length(sText) do begin<br> ptext[i-1] := sText;<br> end;<br> pText:=#0;<br> ismsSend := smsSend(pText,iLen,pPhone);<br> Application.ProcessMessages ;<br> if ismsSend = 1 then begin<br> Memo1.Lines.Add('发送成功!');<br> port_close;<br> end<br> else begin<br> Memo1.Lines.Add('发送失败!'+inttostr(ismsSend));<br> port_close;<br> exit;<br> end;<br><br>end;<br><br>procedure TsmsMain.Button1Click(Sender: TObject);<br>var<br> sCenter : string;<br> i : integer;<br> pCenter : array[0..20] of char;<br>begin<br> {设置通讯口}<br> iWm_init := Wm_init(pchar( trim(eCom.Text) ),pchar( trim(eRate.Text) ));<br> if iWm_init = 0 then begin<br> memo1.Lines.Add('设置通讯口失败!');<br> exit;<br> end;<br> {初始化MORDEM}<br> sWmCommInit := WmCommInit;<br> if sWmCommInit <> 1 then begin<br> Memo1.Lines.Add('初始化MORDEM失败!'+inttostr(iWmCommInit));<br> port_close;<br> exit;<br> end;<br> {设置短信中心号码}<br> sCenter := trim( eCenter.Text );<br> for i := 1 to length(eCenter.Text) do begin<br> pCenter[i-1] := sCenter;<br> end;<br> pCenter:=#0;<br><br> ismsInit := smsInit( pCenter );<br> if ismsInit <> 1 then begin<br> Memo1.Lines.Add('设置短信中心号码失败(2)!'+inttostr(ismsInit));<br> port_close;<br> exit;<br> end;<br><br> Memo1.Lines.Add('置短信中心号码成功!'+inttostr(ismsInit));<br><br>end;<br><br>procedure TsmsMain.BitBtn3Click(Sender: TObject);<br>begin<br> memo1.Clear ;<br>end;<br><br>procedure TsmsMain.BitBtn2Click(Sender: TObject);<br>var<br> sePhone,sCenter,sText : string;<br> pCenter : array[0..20] of char;<br> pPhone : array[0..20] of char;<br> pTime : array[0..12] of char;<br> pText : array[0..140] of char; {接收的缓冲区}<br> i,iLen : integer;<br>begin<br> {设置通讯口}<br> iWm_init := Wm_init(pchar( trim(eCom.Text) ),pchar( trim(eRate.Text) ));<br> if iWm_init = 0 then begin<br> memo1.Lines.Add('设置通讯口失败!');<br> exit;<br> end;<br> {初始化MORDEM}<br> sWmCommInit := WmCommInit;<br> if sWmCommInit <> 1 then begin<br> Memo1.Lines.Add('初始化MORDEM失败!'+inttostr(iWmCommInit));<br> port_close;<br> exit;<br> end;<br> {设置短信中心号码}<br> sCenter := trim( eCenter.Text );<br> for i := 1 to length(eCenter.Text) do begin<br> pCenter[i-1] := sCenter;<br> end;<br> pCenter:=#0;<br> ismsInit := smsInit( pCenter );<br> if ismsInit <> 1 then begin<br> Memo1.Lines.Add('设置短信中心号码失败(3)!'+inttostr(ismsInit));<br> port_close;<br> exit;<br> end;<br> {取存储短信最大数}<br> iIndex := sms_Amount;<br> if iIndex < 0 then begin<br> Memo1.Lines.Add('取存储最大数错误!'+inttostr(iIndex));<br> port_close;<br> exit;<br> end;<br><br> Memo1.Lines.Add('最多可存储短消息条数:'+inttostr(iIndex));<br><br> if iIndex = 0 then begin<br> Memo1.Lines.Add('目前没有短信!'+inttostr(iIndex));<br> port_close;<br> exit;<br> end;<br> {读取短信信息}<br> iLen := 140;<br> for i := 1 to iIndex do begin<br> fillchar(ptext,sizeof(pText),ord(' '));{初始化缓冲区}<br> fillchar(pPhone,sizeof(pPhone),ord(' '));<br> fillchar(pTime,sizeof(pTime),ord(' '));<br> fillchar(pCenter,sizeof(pCenter),ord(' '));<br> iRead := Sms_Read_VC(i,pText,iLen,pPhone,pTime,pCenter);<br> if iRead <> 1 then begin<br> Memo1.Lines.Add('接收第'+inttostr(i)+'条短信失败!'+inttostr(iRead));<br> if i = iIndex then begin<br> // port_close;<br> break;<br> end;<br> continue;<br> end;<br> memo1.Lines.Add('发送号码:'+pPhone+' 时间:'+pTime+'内容:'+pText+'短信中心:'+pCenter);<br> end;<br> {删除短信}<br><br>end;<br><br>procedure TsmsMain.OnFormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> port_close;<br>end;<br>procedure TsmsMain.BitBtn4Click(Sender: TObject);<br>var<br> sePhone,sCenter,sText : string;<br> pCenter : array[0..20] of char;<br> pPhone : array[0..20] of char;<br> pText : array[0..140] of char;<br> i,iLen : integer;<br>begin<br> if eText.Text = '' then begin<br> showmessage('发送短信内容不能为空!');<br> if eText.CanFocus then eText.SetFocus ;<br> exit;<br> end;<br> if ePhone.Text = '' then begin<br> showmessage('对方电话不能为空!');<br> if ePhone.CanFocus then ePhone.SetFocus ;<br> exit;<br> end;<br> {设置通讯口}<br> iWm_init := Wm_init(pchar( trim(eCom.Text) ),pchar( trim(eRate.Text) ));<br> if iWm_init = 0 then begin<br> memo1.Lines.Add('设置通讯口失败!');<br> exit;<br> end;<br> {初始化MORDEM}<br> sWmCommInit := WmCommInit;<br> if sWmCommInit <> 1 then begin<br> Memo1.Lines.Add('初始化MORDEM失败!'+inttostr(iWmCommInit));<br> port_close;<br> exit;<br> end;<br> {设置短信中心号码}<br> sCenter := trim( eCenter.Text );<br> for i := 1 to length(eCenter.Text) do begin<br> pCenter[i-1] := sCenter;<br> end;<br> pCenter:=#0;<br> ismsInit := smsInit( pCenter );<br> if ismsInit <> 1 then begin<br> Memo1.Lines.Add('设置短信中心号码失败(4)!'+inttostr(ismsInit));<br> port_close;<br> exit;<br> end;<br> {发送短信}<br> sePhone := trim( trim( ePhone.Text ) );<br> for i := 1 to length(ePhone.Text) do begin<br>//这是我的注释,关键问题就在这里<br> pPhone[i-1] := sePhone;<br> end;<br> pPhone:= #0;<br><br> iLen := length( eText.Text );<br> sText := trim( eText.Text );<br> fillchar(ptext,sizeof(pText),ord(' '));<br><br> for i := 1 to length(sText) do begin<br> ptext [i-1]:= sText;<br> end;<br> pText:=#0;<br> ismsSend := smsSendText(pText,iLen,pPhone);<br> Application.ProcessMessages ;<br> if ismsSend = 1 then begin<br> Memo1.Lines.Add('发送成功!');<br> port_close;<br> end<br> else begin<br> Memo1.Lines.Add('发送失败!'+inttostr(ismsInit));<br> port_close;<br> exit;<br> end;<br><br>end;<br><br>procedure TsmsMain.BitBtn5Click(Sender: TObject);<br>var<br> sePhone,sCenter,sText : string;<br> pCenter : array[0..20] of char;<br> pPhone : array[0..20] of char;<br> pTime : array[0..12] of char;<br> pText : array[0..140] of char; {接收的缓冲区}<br> i,iLen : integer;<br>begin<br> {设置通讯口}<br> iWm_init := Wm_init(pchar( trim(eCom.Text) ),pchar( trim(eRate.Text) ));<br> if iWm_init = 0 then begin<br> memo1.Lines.Add('设置通讯口失败!');<br> exit;<br> end;<br> {初始化MORDEM}<br> sWmCommInit := WmCommInit;<br> if sWmCommInit <> 1 then begin<br> Memo1.Lines.Add('初始化MORDEM失败!'+inttostr(iWmCommInit));<br> port_close;<br> exit;<br> end;<br> {设置短信中心号码}<br> sCenter := trim( eCenter.Text );<br> for i := 1 to length(eCenter.Text) do begin<br> pCenter[i-1] := sCenter;<br> end;<br> pCenter:=#0;<br><br> ismsInit := smsInit( pCenter );<br><br> if ismsInit <> 1 then begin<br> {ShowMessage('设置失败!');}<br> Memo1.Lines.Add('设置短信中心号码失败(5)!'+inttostr(ismsInit));<br> port_close;<br> exit;<br> end;<br><br> {取存储短信最大数}<br> iIndex := sms_Amount;<br> if iIndex < 0 then begin<br> Memo1.Lines.Add('取存储最大数错误!'+inttostr(iIndex));<br> port_close;<br> exit;<br> end;<br><br> Memo1.Lines.Add('最多可存储短消息条数:'+inttostr(iIndex));<br><br> if iIndex = 0 then begin<br> Memo1.Lines.Add('目前没有短信!'+inttostr(iIndex));<br> port_close;<br> exit;<br> end;<br> {读取短信信息}<br> iLen := 140;<br> while(TRUE) do<br> begin<br> fillchar(ptext,sizeof(pText),ord(' '));{初始化缓冲区}<br> fillchar(pPhone,sizeof(pPhone),ord(' '));<br> fillchar(pTime,sizeof(pTime),ord(' '));<br> fillchar(pCenter,sizeof(pCenter),ord(' '));<br> iRead := ReadNextSms(pText,iLen,pPhone,pTime,pCenter);<br> CASE iRead Of<br> 1:<br> BEGIN<br> Memo1.Lines.Add('接收短信成功,后面还有短信未读出!'+inttostr(iRead));<br> memo1.Lines.Add('发送号码:'+pPhone+' 时间:'+pTime+'内容:'+pText+'短信中心:'+pCenter);<br> END<br> ;<br> 2:<br> BEGIN<br> Memo1.Lines.Add('接收短信成功,后面已经没有短信未读出!'+inttostr(iRead));<br> memo1.Lines.Add('发送号码:'+pPhone+' 时间:'+pTime+'内容:'+pText+'短信中心:'+pCenter);<br> END<br> ;<br> 3:<br> BEGIN<br> Memo1.Lines.Add('缓冲区中已经没有短信未读出!'+inttostr(iRead));<br> BREAK;<br> END<br> ;<br> -1:<br> BEGIN<br> Memo1.Lines.Add('读取失败(可能是串口没有初始化)!'+inttostr(iRead));<br> BREAK;<br> END<br> ;<br> 0:Memo1.Lines.Add('存在无法正确解码的编码!'+inttostr(iRead));<br> END;<br><br> {测试单条}<br> {break;}<br> end;<br> {删除短信}<br><br>end;<br><br>procedure TsmsMain.BitBtn6Click(Sender: TObject);<br>VAR<br> sCenter : string;<br> i : integer;<br> pCenter : array[0..20] of char;<br> smliDial:smallint;<br>begin<br> {设置通讯口}<br> iWm_init := Wm_init(pchar( trim(eCom.Text) ),pchar( trim(eRate.Text) ));<br> if iWm_init = 0 then begin<br> memo1.Lines.Add('设置通讯口失败!');<br> exit;<br> end;<br> {初始化MORDEM}<br> sWmCommInit := WmCommInit;<br> if sWmCommInit <> 1 then begin<br> Memo1.Lines.Add('初始化MORDEM失败!'+inttostr(iWmCommInit));<br> port_close;<br> exit;<br> end;<br> {进行拨号}<br> sCenter := trim( ePhone.Text );<br> for i := 1 to length(ePhone.Text) do begin<br> pCenter[i-1] := sCenter;<br> end;<br> pCenter := #0;<br><br> smliDial := Dial( pCenter );<br><br> if smliDial <> 1 then begin<br> Memo1.Lines.Add('拨号失败!'+inttostr(smliDial));<br> port_close;<br> exit;<br> end;<br><br> Memo1.Lines.Add('拨号成功!'+inttostr(smliDial));<br>end;<br><br>end.