⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdllp.cpp

📁 文本到PDU转换动态链接库
💻 CPP
字号:
//---------------------------------------------------------------------------
/**************************
        程序名:短消息测试程序
        作者:厉小伟
        公司:上海蓝峰电子技术有限公司
        电话:021-63222149
        传真:021-63524268
        邮件:dlxw@china.com
*****************************/
#include <vcl.h>
#include <comm.h>
#pragma hdrstop

#include "TESTDLLP.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TForm1 *Form1;
String int2str(int i);
TCommPort *pcom;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE DLLInst = NULL;
    DLLInst = LoadLibrary("SMSDLL.dll");
    if (DLLInst) {
        About = (void (__stdcall*)()) GetProcAddress(DLLInst,
                                                    "About");
        if (About) About();
    }
    else ShowMessage("Could not load LC.dll");
    //openComm();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
char s[300];

int i,ret=0,sms_len=0;
int flash=0,report=0;
if(ChkReport->Checked )
   report=1;
if(ChkFlash->Checked )
   flash=1;

HINSTANCE DLLInst = NULL;
    DLLInst = LoadLibrary("SMSDLL.dll");
    if (DLLInst) {
        TextToSms = (int (__stdcall*)(char*,char*,char*,int,int ,int *,char*)) GetProcAddress(DLLInst,"TextToSms");
          if (TextToSms)
            ret=TextToSms(Edit3->Text.c_str(),Edit1->Text.c_str(),Edit2->Text.c_str(),flash,report,&sms_len,s);
           Memo2->Text="长度:"+ IntToStr(sms_len)+ ",内容:" +s;
           ShowMessage("长度" +IntToStr(sms_len)+ ",\r内容:"+s);

        }

}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button3Click(TObject *Sender)
{
char s[200];
char csca[100];
char sendtime[100];

char ToNum[100];
char smsnr[200];
int i;
int  csca_len, num_len;
int time_len;
String sms;
HINSTANCE DLLInst = NULL;
    DLLInst = LoadLibrary("SMSDLL.dll");
    if (DLLInst) {
         SmsToText = (int (__stdcall*)(char* ,char*,int * ,char* ,int *,char*,int*,char* )) GetProcAddress(DLLInst,"SmsToText");
           //GetProcAddress(DLLInst,"SmsToText"); 内大小写也要合适

        if (SmsToText){
           i= SmsToText(Memo1->Text.c_str(),csca,&csca_len,ToNum,&num_len,sendtime,&time_len,smsnr);
           strcpy(s,"接收到来自:\r");
           strcat(s,ToNum);
           strcat(s,"\r短消息中心号码:");
           strcat(s,csca);
           strcat(s,"\r发送时间:\r");
           strcat(s,sendtime);
           strcat(s,"\r内容:\r");
           strcat(s,smsnr);
           //sms="接收到来自:";
           //sms+=ToNum;
           //sms+="的短消息:" ;
           //sms+=smsnr;
           ShowMessage(s);
           }
        }
}
//---------------------------------------------------------------------------






//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Memo1->Text="0891683108200105F0240BA13146612544F0000820116161657120124F605FEB67655E2E83F283F2";
       pcom=new TCommPort;

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{


       pcom->WriteString("at+cgmm\r\n");

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button5Click(TObject *Sender)
{
      //  char ch[101];
     //   if (pcom)pcom->ReadString(ch,100);
     //     else
     //     ShowMessage("没有初始化端口");
     //  Edit4->Text=ch;
       
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{

         delete pcom;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button6Click(TObject *Sender)
{


        char s[300];
        char sret[100];
        AnsiString ss;
        int i,ret=0,sms_len=0;
        long tt;
        bool fok=false;
        
        int flash=0,report=0;
        if(ChkReport->Checked)
           report=1;
        if(ChkFlash->Checked)
           flash=1;
        HINSTANCE DLLInst = NULL;
        DLLInst = LoadLibrary("SMSDLL.dll");
        if (DLLInst) {
                TextToSms = (int (__stdcall*)(char*,char*,char*,int,int ,int *,char*)) GetProcAddress(DLLInst,"TextToSms");
                if (TextToSms)
                        ret=TextToSms(Edit3->Text.c_str(),Edit1->Text.c_str(),Edit2->Text.c_str(),flash,report,&sms_len,s);
                         if (ret==0)
                           {
                            ShowMessage("编码出错");
                            return;
                            }
                            Button6->Enabled =false;
                            Memo2->Text="长度:"+ IntToStr(sms_len)+ ",内容:" +s;
                            pcom->SetBaudRate(19200);
                            pcom->SetCommPort(AnsiString("COM"+Edit5->Text).c_str());
                            pcom->OpenCommPort();

                            pcom->WriteString("at+cmgf=0\r\n");
                              tt=GetTickCount();
                              while((GetTickCount()-tt<100)&&!fok)
                              {
                                Application->ProcessMessages();
                                ret=pcom->ReadBytes(sret,99);

                                if (GetTickCount()-tt<0)
                                   tt=GetTickCount();
                                if(AnsiString(sret).Pos(">")>0)
                                 fok=true;

                                }
                             fok=false;
                            pcom->WriteString(AnsiString("at+cmgs=" +  IntToStr(sms_len) + "\r").c_str());
                              tt=GetTickCount();
                              while((GetTickCount()-tt<2000)&&!fok)
                              {
                                Application->ProcessMessages();
                                ret=pcom->ReadBytes(sret,99);

                                if (GetTickCount()-tt<0)
                                   tt=GetTickCount();
                                if(AnsiString(sret).Pos(">")>0)
                                 fok=true;

                                }
                                //
                                pcom->WriteString(s);
                                pcom->WriteString(AnsiString((char)0x1A).c_str());
                                fok=false;
                               tt=GetTickCount();
                                while((GetTickCount()-tt<5000)&&!fok)
                              {

                                ret=pcom->ReadBytes(sret,99);
                                if (GetTickCount()-tt<0)
                                   tt=GetTickCount();
                                   ss+=sret;
                                if(ss.Pos("+CMGS:")>0)
                                 fok=true;

                                }
                                if(fok)
                                  ShowMessage("发送完成。");
                                  else
                                  ShowMessage("发送出错");
                                pcom->CloseCommPort();
                                Button6->Enabled =true;

        }

        //pcom->WriteString("");
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit2Change(TObject *Sender)
{
    if(Edit2->Text.Length()>0)
            Label5->Caption =wcslen(WideString(Edit2->Text));
    else
    Label5->Caption ="0";
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -