我这里也有:
用GSM模块发中文短讯,必须以PDU包的形式发送。我将它写成了Dll,直接调用SMSEncode函数即可得到追后的编码。现将原码公开:
unit EnCodeCompnent;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;    function SMSEncode(s:WideString;Result_Code:pchar):Bool;Stdcall;export;
    function SMSDecode(Input_Code:pchar;Result_Str:pchar):Bool;Stdcall;export;
    function MakePDU(DestNumber:pchar;Content:pchar;Result_String:pchar):Bool;stdcall;export;
    function ConvertPhoneNum(strNum:string):string;
    function Transposition(instr:pchar;Result_str:pchar):Bool;stdcall;export;//将一个字符串两两交换位置
    { Public declarations }implementation
function SMSEncode(s:WideString;Result_Code:pchar):Bool;
var
  i,len:Integer;
  cur:Integer;
  t,temp:String;
begin
if length(s)>0 then
  begin
    len:=Length(s);
    i:=1;
    while i<=len do
      begin
        cur:=ord(s[i]);
        //BCD convert
        FmtStr(t,'%4.4X',[cur]);
        temp:=temp+t;
        inc(i);
      end;
    StrCopy(Result_Code,pchar(temp));
    Result:=true;
  end
else
  Result:=false;
end;function SMSDecode(Input_Code:pchar;Result_Str:pchar):Bool;
var
  str:string;
  i:integer;
  temp:string;
  A_PWideChar:array[0..300] of widechar;
  R_String:string;
  A_integer:integer;
begin
  str:=string(Input_Code);
  R_String:='';
  if length(str)<=0 then
    begin
      Result:=false;
      exit;
    end;
  i:=0;
  while i<length(str) do
    begin
      temp:=copy(str,i+1,4);
      A_integer:=strtoint('$'+temp);
      move(A_integer,A_PWideChar[i div 4],sizeof(A_PWideChar[i div 4]));
      inc(i,4);
    end;
  A_PWideChar[length(str) div 4]:=#0;
  R_String:=WideCharToString(@A_PWideChar);
  StrCopy(Result_Str,pchar(R_String));
  Result:=true;
end;
function MakePDU(DestNumber:pchar;Content:pchar;Result_String:pchar):Bool;
const
  lenSmsInfo='00';
  firstOctet='11';
  TPMessageReference='00';
  TypeOfAddress='91';
  TpId='00';
  TpDcs='08';//"00" is 7 bit encode "08" is 8 bit encode;
  TPValidityPeriod='AA';//aa is 4 day
var
  DestPhoneNum:string;
  AddressLength:string;
  TpUserData:string;
  TPUserDataLength:string;
  temp:WideString;
  Tmp_Pchar:pchar;
  Rlt_str:string;
begin
  if (DestNumber='') or (Content='') then
    begin
      Result:=false;
      exit;
    end
  else
    begin
      DestPhoneNum:=ConvertPhoneNum(DestNumber);
      AddressLength:=format('%2.2X',[length(DestNumber)]);
      temp:=Content;
      Tmp_Pchar:=StrAlloc(1000);
      if SMSEncode(temp,Tmp_Pchar) then
        TpUserData:=string(Tmp_Pchar);
      if TpDcs='08' then
        TPUserDataLength:=format('%2.2X',[length(TpUserData) div 2])
      else
        TPUserDataLength:=format('%2.2X',[((length(TpUserData) div 2)*8) div 7]);
      Rlt_str:=lenSmsInfo
              +firstOctet
              +TPMessageReference
              +AddressLength
              +TypeOfAddress
              +DestPhoneNum
              +TpId
              +TpDcs
              +TPValidityPeriod
              +TPUserDataLength
              +TpUserData;//TpUserData have to Encoded;
      StrCopy(Result_String,pchar(Rlt_str));
      Result:=true;
     end;
end;function ConvertPhoneNum(strNum:string):string;
var
i:integer;
str:string;
A_Pchar:pchar;
begin
  str:=strNum;
  i:=length(str);
  if odd(i) then
    begin
      str:=str+'F';
      A_Pchar:=StrAlloc(40);
      if Transposition(pchar(str),A_pchar) then
        result:=string(A_Pchar)
      else
        result:='Null';
    end
  else
    begin
      A_Pchar:=StrAlloc(40);
      if Transposition(pchar(str),A_pchar) then
        result:=string(A_Pchar)
      else
        result:='Null';
    end;
end;function Transposition(instr:pchar;Result_str:pchar):Bool;
var
  i:integer;
  temp:string;
  destStr:string;
  In_String:string;
begin
if length(instr)>0 then
  begin
    destStr:='';
    In_String:=string(instr);
    setlength(In_String,length(In_String));
    i:=1;
    while i<length(In_String) do
      begin
        temp:=In_String[i+1]+In_String[i];
        destStr:=destStr+temp;
        inc(i,2);
      end;
    StrCopy(Result_Str,pchar(destStr));
    result:=true;
  end
else
  begin
    result:=false;
  end;
end;

解决方案 »

  1.   

    部分程序:
    mplementation{$R *.DFM}
    //=============DLL 函数调用声明 开始 =========
        procedure ConnectToMobile;stdcall; external 'SMSLIB.DLL';
        procedure DisconnectToMobile;stdcall; external 'SMSLIB.DLL';
        Function  IsConnected:boolean;stdcall; external 'SMSLIB.DLL';
        Function  IsBusy:boolean;stdcall; external 'SMSLIB.DLL';
        procedure InitMobile;stdcall; external 'SMSLIB.DLL';
        procedure SetSMC(SMC:PChar);stdcall; external 'SMSLIB.DLL';
        Function SendSMS(phone,text:PChar):boolean;stdcall; external 'SMSLIB.DLL';
        Function ReadSMS(Text,sendnum,smc,time:PChar):boolean;stdcall; external 'SMSLIB.DLL';
    //=============DLL 函数调用声明 结束 =========procedure TForm1.Button1Click(Sender: TObject);
    begin
        ConnectToMobile;
        memo2.Lines.Add ('已经发出连接命令。');
        sleep(4000);     //等待4秒,等待手机准备好
        while not IsConnected do ;  //直到连接成功    memo2.Lines.Add ('已经连接到手机。');
        InitMobile;
        memo2.Lines.Add ('已经初始化。');
        SetSMC(PChar(SMC.Text ));
        memo2.Lines.Add ('短信中心设置成功。');end; 
      

  2.   

    这个程序很有意思,先DOWN下来!@
      

  3.   

    cg1120(代码最优化-§新年祝福你,好运伴着你§):
    谢谢你,首先。
    可是,你的第一个帖子和第二个帖子之间有什么联系么?好像你的一个回帖是进行字符串的加密和解密,以及进行手机号码解析的。而第二个帖子则是在申明了一些你自己的dlls以后在紧跟着的代码中就进行了调用。可是这些dll是怎么实现的呢?不知道能否给一些思路或者来一点代码看看?另外,我还想知道我所贴出来的那些代码是否可以运行?
      

  4.   

    sysu(死树):
    装了地呀。你在你自己的机器上运行通过了么?