?? smspdu.cpp
字號:
// smspdu.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "smspdu.h"
#include "sms.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
char* m_strSmsCenter="8613800100500";
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CSmspduApp
BEGIN_MESSAGE_MAP(CSmspduApp, CWinApp)
//{{AFX_MSG_MAP(CSmspduApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSmspduApp construction
CSmspduApp::CSmspduApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CSmspduApp object
extern "C" _declspec(dllexport) bool CloseComm(HANDLE hComm)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return CloseHandle(hComm);
}
extern "C" _declspec(dllexport) HANDLE OpenComm(const char* pPort, int nBaudRate, int nParity, int nByteSize, int nStopBits)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HANDLE hComm;
DCB dcb; // 串口控制塊
COMMTIMEOUTS timeouts = { // 串口超時控制參數
100, // 讀字符間隔超時時間: 100 ms
1, // 讀操作時每字符的時間: 1 ms (n個字符總共為n ms)
500, // 基本的(額外的)讀超時時間: 500 ms
1, // 寫操作時每字符的時間: 1 ms (n個字符總共為n ms)
100}; // 基本的(額外的)寫超時時間: 100 ms
hComm = CreateFile(pPort, // 串口名稱或設備路徑
GENERIC_READ | GENERIC_WRITE, // 讀寫方式
0, // 共享方式:獨占
NULL, // 默認的安全描述符
OPEN_EXISTING, // 創建方式
0, // 不需設置文件屬性
NULL); // 不需參照模板文件
if(hComm == INVALID_HANDLE_VALUE) return NULL; // 打開串口失敗
GetCommState(hComm, &dcb); // 取DCB
dcb.BaudRate = nBaudRate;
dcb.ByteSize = nByteSize;
dcb.Parity = nParity;
dcb.StopBits = nStopBits;
SetCommState(hComm, &dcb); // 設置DCB
SetupComm(hComm, 4096, 1024); // 設置輸入輸出緩沖區大小
SetCommTimeouts(hComm, &timeouts); // 設置超時
return hComm;
}
extern "C" __declspec(dllexport) HANDLE initializeCom(char *devname)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
DCB dcb;
HANDLE FP;
FP=CreateFile(devname,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if (FP!=(HANDLE) -1)
{
PurgeComm(FP,PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);
GetCommState(FP,&dcb);
dcb.BaudRate = CBR_9600;
dcb.ByteSize = 8;
dcb.StopBits = ONESTOPBIT;
dcb.Parity=NOPARITY;
SetCommState(FP,&dcb);
}
return FP;
}
extern "C" __declspec(dllexport) bool SendShortMessage(HANDLE Fcomm,CString send_number,CString send_msg,SM_PARAM *sm_param_temp)
{
char SCA[16]; // 短消息服務中心號碼(SMSC地址)
char TPA[16]; // 目標號碼或回復號碼(TP-DA或TP-RA)
char TP_PID; // 用戶信息協議標識(TP-PID)
char TP_DCS; // 用戶信息編碼方式(TP-DCS)
char TP_UD[161]; // 原始用戶信息(編碼前或解碼后的TP-UD)
int i,t;
//strcpy(sm_param_temp->SCA,"8613800100500");
strcpy(sm_param_temp->SCA,m_strSmsCenter);
t= send_number.GetLength()+2;
for(i=2;i<t;i++)
TPA[i]=send_number.GetAt(i-2);
TPA[0]='8';
TPA[1]='6';
TPA[t]='\0';
strcpy(sm_param_temp->TPA,TPA);
if(send_number.GetLength()<11)
{
AfxMessageBox("請輸入正確的號碼!");
return false;
}
for(i=0;i<send_msg.GetLength();i++)
TP_UD[i]=send_msg.GetAt(i);
TP_UD[i+1]='\0';
strcpy(sm_param_temp->TP_UD,TP_UD);
sm_param_temp->TP_DCS=0x8;
sm_param_temp->TP_PID=0x0;
return gsmSendMessage(Fcomm,sm_param_temp);
}
extern "C" __declspec(dllexport) int ReceiveMessage(HANDLE Fcomm,SM_PARAM *sm_param,int index)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: Add your control notification handler code here
/*
int recordnum=0;
int i,j,length;
char* stemp;
recordnum=gsmReadMessage(Fcomm,&sm_param);
if(recordnum<=0)
return NULL;
stemp=sm_param.TP_UD;
return stemp;
*/
return gsmReadMessage(Fcomm,sm_param,index);
}
extern "C" __declspec(dllexport) int ReceiveAllMessage(HANDLE Fcomm,SM_PARAM *sm_param)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: Add your control notification handler code here
return gsmReadAllMessage(Fcomm,sm_param);
}
extern "C" __declspec(dllexport) void Message()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
::MessageBox(NULL,"aaaaaaaaaaa","nnnnn",MB_OK);
}
//刪除所有短消息
extern "C" __declspec(dllexport) bool DeleteAllMessage(HANDLE Fcomm)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
char* cmd="AT+CMGD=1,4\r";
return WriteComm(Fcomm,cmd, strlen(cmd));
}
//刪除某條短消息
extern "C" __declspec(dllexport) bool DeleteMessage(HANDLE Fcomm,int index)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmDeleteMessage(Fcomm,index);
}
extern "C" __declspec(dllexport) bool SetSendModule(HANDLE Fcomm,int loopback)
{
char cmd[20];
char temp[2];
bool m_bSign;
sprintf(cmd, "ATE");
sprintf(temp, "%d", loopback);
strcat(cmd,temp);
strcat(cmd,"\r");
WriteComm(Fcomm,cmd, strlen(cmd));
Sleep(10);
sprintf(cmd, "AT+CMGF=0\r");
m_bSign=WriteComm(Fcomm,cmd, strlen(cmd));
Sleep(10);
return m_bSign;
}
extern "C" __declspec(dllexport) void SetSmsCenter(char* pStrCenter)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_strSmsCenter=pStrCenter;
return;
}
extern "C" __declspec(dllexport) int Decode8bit(const unsigned char *pSrc, char *pDst, int nSrcLength)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmDecode8bit(pSrc, pDst, nSrcLength);
}
extern "C" __declspec(dllexport) int Encode8bit(const char *pSrc, unsigned char *pDst, int nSrcLength)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmEncode8bit(pSrc, pDst, nSrcLength);
}
extern "C" __declspec(dllexport) int DecodeUcs2(const unsigned char* pSrc, char* pDst, int nSrcLength)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmDecodeUcs2(pSrc, pDst, nSrcLength);
}
extern "C" __declspec(dllexport) int EncodeUcs2(const char* pSrc, unsigned char* pDst, int nSrcLength)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmEncodeUcs2(pSrc, pDst, nSrcLength);
}
extern "C" __declspec(dllexport) int Decode7bit(const unsigned char* pSrc, char* pDst, int nSrcLength)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmDecode7bit(pSrc, pDst, nSrcLength);
}
extern "C" __declspec(dllexport) int Encode7bit(const char* pSrc, unsigned char* pDst, int nSrcLength)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmEncode7bit(pSrc,pDst,nSrcLength);
}
extern "C" __declspec(dllexport) int String2Bytes(const char* pSrc, unsigned char* pDst, int nSrcLength)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmString2Bytes(pSrc,pDst,nSrcLength);
}
extern "C" __declspec(dllexport) int Bytes2String(const unsigned char* pSrc, char* pDst, int nSrcLength)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmBytes2String(pSrc,pDst,nSrcLength);
}
extern "C" __declspec(dllexport) int DecodePdu(const char* pSrc, SM_PARAM* pDst)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmDecodePdu(pSrc,pDst);
}
extern "C" __declspec(dllexport) int EncodePdu(const SM_PARAM* pSrc, char* pDst)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmEncodePdu(pSrc,pDst);
}
extern "C" __declspec(dllexport) int SerializedNumbers(const char* pSrc, char* pDst, int nSrcLength)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmSerializeNumbers(pSrc,pDst,nSrcLength);
}
extern "C" __declspec(dllexport) int InvertedNumbers(const char* pSrc, char* pDst, int nSrcLength)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return gsmInvertNumbers(pSrc, pDst,nSrcLength);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -