This article copyright statement: 1) Any programming enthusiast, netizen can download and use the following source code in non-commercial purposes. 2) Use friends who use all or part of the code below, please indicate: http://blog.9cbs.net/dfman3) Reserved copyright to commercial purposes is this: 1) Buy a support set to AT instructions Mobile phone, I bought Siemens; 2) Buy the data cable with the mobile phone, allow the phone to link with the computer serial port; 3) Of course, you have a SIM / UIM card; 4) Write a program according to the algorithm below; 5) The next is to send and receive text messages. This class is part of the entire project, not to ensure the complete code, but can guarantee the integrity of the algorithm and ideas. Typedef struct _sms_recv // Receive information notification structure {long lmsgtype; // SMS type: msgtype_sms or msgtype_report char szsmsc [32]; // SMS center char ssender [32]; // sender number if lmsgtype == msgtype_report , Is the target mobile phone number Char Sztime [32]; // transmit time char SZMSG [512]; // information} SMS_RECV;
// Short message team buffer pool struct shortmsgpool {handle hsmphavedata; handle hsmpidle; dword dwsize; char * pdata;
// Send short message buffer pool struct submitpool {handle hspdeliver; handle hspidle; dword dwsize; char * pdata;
/ / Receive short message buffer pool Struct DeliverPool {handle hdpdeliver; // Delivered Event handle handle hndle hdpidle; / / Indicates the cushion pool empty event handle DWORD DWSIZE; / / Request data size, in byte as unit char * PDATA ; // request data storage buffer}; class cgsmphone {public: long getRecvnum () {return (m_dwsmnumberinpool);} long getMobilename (char * pname); long getsmcontent (void) {return (m_dwsmcontent == 0? -1 : m_dwSMContent);} long GetShortMsg (SMS_Recv * pSms); long GetShortMsg2 (char * pNo, char * pMsg, char * pTime); long Send (char * pNo, char * pMsg, BOOL bReport, BOOL bHandFree, BOOL bAsyn); Bool Close (); BOOL OPEN (int Nport = 1, int NBAUD = 19200);
Bool isopened (void) {return (m_bopened);
Void DeliveReread (); void submitthread ();
CGSMPHONE (); Virtual ~ cgsmphone ();
HWND M_HWND; DWORD M_DWTIMEOUT; CSTRING M_STRSMCENTER;
protected:
DWORD Deliver (char * & pData); DWORD Submit (char * szBuffer, DWORD dwLen); DWORD PDUEncodeEng (char * pMsg, char * & pResultData); DWORD PDUEncodeChn (char * pMsg, char * & pResultData); DWORD PDUDecodeEng (char * pMsg, char * & pResultData); DWORD PDUDecodeChn (char * pMsg, char * & pResultData); char * NumberEncode (char * pPhoneNumber); bool NumberDecode (char * szNumber, int nLen); void Str2StrArr (CString strTemp, CStringArray & sa, char cDelimiter); DWord ReadStringFromComm (Char * Szbuffer, DWORD DWBUFLEN); DWord Readcomm (CHAR * SZBuffer, DWORD DWBUFLEN); BOOL WRITECOMM (CONST Char * Buffer, DWORD SIZE);
bool FreeShortMsgPool (void); bool FreeDeliverPool (void); bool FreeSubmitPool (void); bool CreateShortMsgPool (DWORD dwNum); bool CreateDeliverPool (DWORD dwNum); bool CreateSubmitPool (DWORD dwNum);
SubmitPool * m_pSPool; HANDLE * m_phSPDeliver; HANDLE * m_phSPIDLE; DeliverPool * m_pDPool; HANDLE * m_phDPDeliver; HANDLE * m_phDPIDLE; ShortMsgPool * m_pSMPool; HANDLE * m_phSMPHaveData; HANDLE * m_phSMPIDLE;
Handle M_HSYSTEMEXIT; HANDLE M_HIDCOMDEV;
Long m_dwsmnumberinpool; dword m_dwthreadpool; dword m_dwsmcontentpoolnum; dword m_dwsmcontent; bool m_bopet; bool m_bstarted;
Overlapped m_overlapped
Critical_section m_cscomm;
CString M_STRCOMMBUFFER; CSTRING M_STRMOBILENAME;}; # include "gsmphone.h" #include
Void submitthreadfun (lpvoid lpparam) {cgsmphone * pgsmphone = (cgsmphone *) lpparam; pgsmphone-> submitthread ();
Void DeliveRThreadFun (lpvoid lpparam) {cgsmphone * pgsmphone = (cgsmphone *) lpparam; pgsmphone-> DeliverthRead ();
//// construction / destruction //
CGSMPhone :: CGSMPhone () {m_hIDComDev = NULL; m_hSystemExit = NULL; m_hWnd = NULL; m_bOpened = false; m_bStarted = false; m_dwTimeout = 5; m_dwThreadPoolNum = 5; m_dwSMContent = 0; m_dwSMNumberInPool = 0;
M_STRSMCENTER = ""; m_strcommbuffer = ""; m_strmobilename = ""; // HDDELIVER = CreateEvent (NULL, FALSE, FALSE, NULL);}
CGSMPHONE :: ~ cgsmphone () {
}
Bool cgsmphone :: createSubmitPool (DWORD DWNUM) {Try {m_pspool = new submitPool [dwnum 1]; m_phspdeliver = new handle [dwnum 1]; m_phspidle = new handle [dwnum 1];
For (DWORD DW = 0; DW M_phspdeliver [dw] = m_phspidle [dw] = m_hsystemexit;} catch (...) {return (false) Return (True); bool CGSMPhone :: FreeSubmitPool () {try {for (DWORD dwCount = 0; dwCount Bool CGSMPHONE :: CreateDeliverPool (DWORD DWNUM) {Try {m_pdpool = New DeliverPool [DWNUM 1]; m_phdpdeliver = new handle [dwnum 1]; m_phdpidle = new handle [dwnum 1]; For (DWORD DW = 0; DW Return (True); bool CGSMPhone :: FreeDeliverPool () {try {for (DWORD dwCount = 0; dwCount Bool CGSMPHONE :: Createshortmsgpool (DWORD DWNUM) {Try {m_psmpool = new short msgpool [dwnum]; m_phsmphavedata = new handle [dwnum]; m_phsmpidle = new handle [dwnum]; For (DWORD DW = 0; DW Return (True); bool CGSMPhone :: FreeShortMsgPool () {try {for (DWORD dwCount = 0; dwCount EnterCriticalSection (& m_csComm); (& m_csComm) LeaveCriticalSection;; bResult = WriteFile (m_hIDComDev, buffer, size, & dwBytesSent, & m_Overlapped) if (! BResult) {if ((GetLastError () == ERROR_IO_PENDING)) {if (WaitForSingleObject (m_Overlapped.hEvent , 1000) == WAIT_OBJECT_0) {GetOverlappedResult (m_hIDComDev, & m_Overlapped, & dwBytesSent, FALSE); if (dwBytesSent == size) {Sleep (100); return (true);}}}} else {Sleep (100); return ( Return (false);} DWORD CGSMPHONE :: Readcomm (Char * szbuffer, dword dwbuffler) {bool bool = true; dword dwevtmask = 0; dword dwerror = 0; dword dwbytesread = 0; comStat Comstat; EntercriticalSection; ClearcomMerror (M_HidComDev, & Dwrror, & Comstat); if (Comstat.cbinque == 0) {LeaveCritics; Return (0);} DwbytesRead = Comstat.cbinque; bResult = ReadFile (m_hIDComDev, szBuffer, dwBytesRead, & dwBytesRead, & m_Overlapped); LeaveCriticalSection (& m_csComm); if (bResult!) {if (GetLastError () == ERROR_IO_PENDING) {Sleep (100); WaitForSingleObject (m_Overlapped.hEvent, 2000); GetOverlappedResult (m_hIDComDev, & m_Overlapped, & dwBytesRead, FALSE);}} Sleep (200); return (dwBytesRead);} DWORD CGSMPhone :: ReadStringFromComm (char * szBuffer, DWORD dwBufLen) {char szBuf [1024]; DWORD dwRet = 0; while (1) {SLEEP (100); MEMSET (SZBUF, 0, 1024); dwret = readcomm (SZBUF, 1024); if (dwret> 0) {m_strcommbuffer = szbuf; if (m_strcommbuffer.find ("ok") = = -1) Continue; if (m_strcommbuffer.find ('/ r')> 0) Break;} else {Break;}} IF (! m_strcommbuffer.isempty ()) {int nfirst = m_strcommbuffer.find ("ok"); if (nfirst> 0) {INT nNext = m_strcommbuffer.find ('/ r', nfirst); if (nNext> 0) {int nStrLen = nNext 1; strncpy (szBuffer, (LPCTSTR) m_strCommBuffer, nStrLen); if (m_strCommBuffer.GetLength ()> nStrLen) {m_strCommBuffer = m_strCommBuffer.Right (m_strCommBuffer.GetLength () - nStrLen);} else {m_strCommBuffer (); (DWORD) nStrlen;}} nfirst = m_strcommbuffer.find (" cmti:"); if (nfirst> 0) {INT nNext = m_strcommbuffer.Find ('/ r', nfirst) ; if (nNext> 0) {int nStrLen = nNext 1; strncpy (szBuffer, (LPCTSTR) m_strCommBuffer, nStrLen); if (m_strCommBuffer.GetLength ()> nStrLen) {m_strCommBuffer = m_strCommBuffer.Right (m_strCommBuffer.GetLength () - nstrlen);} else {m_strcommbuffer.empty ();} return ((dword) nstrlen;}} nfirst = m_strcommbuffer.find (">"); if (nfirst> 0) {INT nNext = m_s trCommBuffer.Find ( '', nFirst); if (nNext> 0) {int nStrLen = nNext 1; strncpy (szBuffer, (LPCTSTR) m_strCommBuffer, nStrLen); if (m_strCommBuffer.GetLength ()> nStrLen) {m_strCommBuffer = m_strCommBuffer .Right (m_strcommbuffer.getLength () - nstrlen;} else {m_strcommbuffer.empty ();} return ((dword) nstrlen;}}} Return (0);} DWORD CGSMPhone :: Submit (char * szBuffer, DWORD dwLen) {try {DWORD dwWaitRet = WaitForMultipleObjects (m_dwThreadPoolNum 1, m_phSPIDLE, FALSE, INFINITE); if (dwWaitRet == WAIT_OBJECT_0 m_dwThreadPoolNum) return (0); m_pSPool [dwWaitRet] .pdata = new char [dwlen]; CopyMemory (m_pspool [dwweitret] .pdata, szbuffer, dwlen; m_pspool [dwweitret] .dwsize = dwlen; setEvent (m_pspool [dwaitret] .hspdeliver);} catch (...) { return (0);} return (dwLen);} DWORD CGSMPhone :: Deliver (char * & pData) {try {DWORD dwWaitRet = WaitForMultipleObjects (m_dwThreadPoolNum 1, m_phDPDeliver, FALSE, m_dwTimeout * 1000); if (dwWaitRet == WAIT_OBJECT_0 m_dwThreadPoolNum) return (0); if (dwWaitRet = WAIT_TIMEOUT) {DWORD dwDataLen = m_pDPool [dwWaitRet] .dwSize;! pData = new char [dwDataLen 1]; ZeroMemory (pData, dwDataLen 1); CopyMemory (pData, m_pDPool [ DWWAITRET] .pdata, dwdatalen; delete [] m_pdpool [dwaitret] .pdata; setEvent (m_pdpool [dwwaitret] .hdpidle); Return (dwdatal EN);}} catch (...) {return (0);} return (0);} void CGSMPhone :: SubmitThread () {while (1) {try {DWORD dwWaitRet = WaitForMultipleObjects (m_dwThreadPoolNum 1, m_phSPDeliver, FALSE, INFINITE); if (dwWaitRet == WAIT_OBJECT_0 m_dwThreadPoolNum) break; int n = 0; while (1 ) {IF (m_pspool [dwwaitret] .pdata, m_pspool [dwaitret]) Break; if ((((N ) == 5) Break; Sleep (1000);} delete [] m_pspool [dwaitret]. PDATA; setEvent (m_pspool [dwaitret] .hspidle); Sleep (200);} catch (...) {breaf;}}} Void cgsmphone :: DeliveRThread () {while (1) {Try {char szbuffer [1024] = {0}; dword dwreadret = readstringFromComm (szbuffer, 1024); if (dwreadret> 0) {char * pfirst; char * pnext; IF (SZBuffer, " CMTI:")! = null) {pfirst = Strchr (szbuffer, ','); pfirst ; if (pfirst! = null) {pNext = strchr (Pfirst, '/ R' ); If (pNext! = Null) {int LEN = pnext - pfirst; if (len <= 0) Continue; char SZCMD [30] = {0}; Memcpy (SZCMD, "AT CMGR =", 8); Memcpy (SZCMD 8, PFirst, Len); SZCMD [8 LEN] = '/ R'; Submit (SZCMD, LEN 9);}}} Else IF (SZBuffer, "At CMGR")! = NULL) {pfirst = strchr (szbuffer, '='); pfirst ; if (pfirst! = Null) {pNext = strchr (pfirst, '/ n'); if (pNext! = Null) {INT LEN = PNext - pfirst; if (len <= 0) Continue; char SZCMD [30] = {0}; Memcpy (SZCMD, "AT CMGD =", 8); Memcpy (SZCMD 8, PFIRST, LEN); SZCMD [8 LEN] = '/ R'; Submit (SZCMD, LEN 9);}} PNEXT = STRSTR (SZBuffer, " CMGR:"); if (pnext! = null) {PFirst = Strchr (PNext, '/ n'); while (pfirst [0] == '/ r' || pfirst [0] == '/ n') PFIRST ; if (pfirst! = null) {pNext = strchr (pfirst, ' / r '); if (pnext! = null) {pnext [0] =' / 0 '; dword dwaitret = WaitForMultipleObjects (m_dwSMContentPoolNum, m_phSMPIDLE, FALSE, 1000); if (! DwWaitRet = WAIT_TIMEOUT) {DWORD dwMsgLen = strlen (pFirst); m_pSMPool [dwWaitRet] .pData = new char [dwMsgLen]; CopyMemory (m_pSMPool [dwWaitRet] .pData, pFirst , dwMsgLen); m_pSMPool [dwWaitRet] .dwSize = dwMsgLen; SetEvent (m_pSMPool [dwWaitRet] .hSMPHaveData); InterlockedIncrement (& m_dwSMNumberInPool);! if (m_hWnd = NULL) :: SendMessage (m_hWnd, PHONE_SMS_RECV, 0, 0);} else {if (m_hWnd = NULL!) :: SendMessage (m_hWnd, PHONE_SMS_RECV_BUF_OVERFLOW, 0, 0);}}}}} else if (! strstr (szBuffer, "AT ") = NULL) {DWORD dwWaitRet = WaitForMultipleObjects (m_dwThreadPoolNum 1 , M_PHDPIDLE, FALSE, 1000); if (dwwaitret == Wait_Object_0 m_dwthreadpoolnum) Break; if (dwweitret! = wait_timeout) {m_pdpool [dwwaitret] .pdata = new char [dwreadret]; copyMemory _pDPool [dwWaitRet] .pData, szBuffer, dwReadRet); m_pDPool [dwWaitRet] .dwSize = dwReadRet; SetEvent (m_pDPool [dwWaitRet] .hDPDeliver);}}}} catch (...) {break;} if (WaitForSingleObject (m_hSystemExit , 0)! = Wait_timeout) Return;}} BOOL CGSMPHONE :: NumberDecode (Char * Sznumber, INT LEN) {IF (len == 0 || Sznumber == Null) Return (false); Char C; for (int N = 0; n Char * cgsmphone :: NumBerencode (char * pphonenumber) {char * szdata; szdata = new char [40]; MEMSET (SZDATA, 0, 40); IF (PPHONENUMBER [0] == ' ') {Memcpy (SZData, PPhoneNumber 1, Strlen (PPHONENUMBER) - 1);} else {Memcpy (SZDATA, PPHONENUMBER, STRLEN (PPHONENUMBER);} IF (Strlen (SZDATA)% 2! = 0) {SZDATA [Strlen (SZDATA)] = 'f';} Char C; for (int N = 0; n Return szdata;} DWORD CGSMPHONE :: PDudecodechn (Char * PMSG, Char * & PRESULTDATA) {IF (PMSG == NULL) RETURN (0); int LEN = Strlen (PMSG); if (len% 2! = 0) Return (0); LPWSTR LPSZW = New Wchar [LEN / 2 1]; MEMSET (LPSZW, 0, LEN 2); Byte * P = (Byte *) LPSZW; INT i = 0, J = 0; char sztemp [3] = { 0}; While (I LEN = J; PRESULTDATA = New Char [LEN 1]; MEMSET (PRESULTDATA, 0, LEN 1); Widechartomultibyte (CP_ACP, 0, LPSZW, -1, PRESULTDATA, LEN, NULL, FALSE); delete [] lpsz; Return (LEN); DWORD CGSMPHONE :: PDudecodeeng (char * pmsg, char * & presultdata) {if (pmsg == null) Return (0); int Len = strlen (PMSG); if (len% 2! = 0) Return (0); Char psz [3] = {0}; byte b; int i = 0, j = 0; byte * ptemp; ptemp = new byte [len / 2]; MEMSET (PTEMP, 0, LEN / 2); While (I LEN = J; i = 0; J = 0; PRESULTDATA = New Char [LEN 20]; MEMSET (PRESULTDATA, 0, LEN 20); char * pcur = preSultdata; while (i Return (PCur - PRESULTDATA); DWORD CGSMPhone :: PDUEncodeChn (char * pMsg, char * & pResultData) {int nLen = MultiByteToWideChar (CP_ACP, 0, pMsg, -1, NULL, NULL); LPWSTR lpszW = new [nLen] WCHAR; MultiByteToWideChar (CP_ACP, 0, pMsg , -1, lpszw, nlen; DWORD dwresultsize = (NLEN-1) * Sizeof (Wchar) * 2; PRESULTDATA = New Char [dwresultsize]; char sztemp [3] = {0}; for (int i = 0, j = 0; J DWord cgsmphone :: PDUENCODEENG (CHAR * PMSG, Char * & PRESULTDATA) {IF (PMSG == NULL) RETURN (0); int NMSGLEN = Strlen (PRESULTDATA = New Char [nmsglen * 2]; MEMSET (PRESULTDATA, 0 , NMSGLEN * 2); CHAR * PCUR = PRESULTDATA; INT i = 0, J = 0; While (i IF ((NPOS = strTemp.Find (cdelimiter))! = -1) {sa.add (strTemp.Left (npos)); strTemp = strtemp.mid (Npos 1);} else {if (! " ()) sa.add (strTemp); Break;}}} bool CGSMPhone :: Open (int nPort, int nBaud) {char szPort [15]; wsprintf (szPort, "COM% d", nPort); m_hIDComDev = CreateFile (szPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | File_flag_overlapped, null); if (m_hidcomdev == null) return (false); Memset (& m_overlapped, 0, sizeof (overlapped)); m_overlapped.hevent = CreateEvent (Null, True, False, NULL) DCB dcb; dcb.DCBlength = sizeof (DCB); GetCommState (m_hIDComDev, & dcb); dcb.BaudRate = nBaud; dcb.ByteSize = 8;!! If (SetCommState (m_hIDComDev, & dcb) || SetupComm (m_hIDComDev, 10000, 10000 || m_overlapped.hevent == null) {dWord dwerror = getLastError (); if (m_overlapped.hevent! = Null) CloseHandle (m_overlapped.hevent); CloseHandle (M_HIDCOMDEV); return (false);} M_Bopened = True; InitializeCriticalsection; Sleep (2000); char szbuffer [1024] = {0}; dword dwret = 0; Try {Sprintf (SZBuffer, "AT / R"); WriteComm (SZBuffer, 3); Sleep (200); Memset (Szbuffer, 0, 1024); IF (ReadStringFromComm (Szbuffer, 1024) == 0) {CloseHandle (m_overlapped .hevent); CloseHandle (m_hidcomdev); deletecriticalsection; return (false);} Memset (SZBuffer, 0, 1024); Sprintf (Szbuffer, "AT & F E1 / R"); WriteComm (Szbuffer, 8); SLEEP 200); memset (szBuffer, 0, 1024); if (ReadStringFromComm (szBuffer, 1024) == 0) {CloseHandle (m_Overlapped.hEvent); CloseHandle (m_hIDComDev); DeleteCriticalSection (& m_csComm); return (false);} MEMSET (SZBuffer, 0, 1024); Sprintf (Szbuffer, "AT CNMI = 1, 1, 0, 2, 1 / R"); WriteComm (Szbuffer, 18); Sleep (200); MEMSET (Szbuffer, 0, 1024); f (SZBuffer, 1024) == 0) {CloseHandle (m_overlapped.hevent); CloseHandle (M_HIDCOMDEV); DeleteCriticalSection; Return (false);} MEMSET (SZBuffer, 0, 1024); Sprintf (SZBuffer, "AT CPMS? / R"); WriteComm (Szbuffer, 9); Sleep (200); Memset (Szbuffer, 0, 1024); dwret = readstringFromComm (Szbuffer, 1024); if (dwret> 0) {char * pdest = strstr (szbuffer, " cpms:"); if (pdest! = Null) {cstring straTemp = CSTRING (PDEST 7, 15); CStringArray Satemp; Str2strarr ( Strtemp, Satemp, ','); IF (Satemp.getsize ()> 3) m_dwsmcontent = atoi (Satemp.getat (2));}} IF (m_dwsmcontent> 0 && m_dwsmcontent <50) {m_dwsmcontentpoolnum = m_dwsmcontent;} else {m_dwsmcontentpoolnum = 30; MEMSET (SZBuffer, 0, 1024); Sprintf (SZBuffer, "AT CGMM / R"); WriteComm (SZBuffer, 8); Sleep (200); Memset (Szbuffer, 0, 1024); if (ReadStringFromComm (Szbuffer, 1024 )> 0) {char * pfirst = strchr (szbuffer, '/ r'); char * pnext = null; while (pfirst [0] == '/ r' || pfirst [0] == '/ n') PFirst ; if (pfirst! = null) pnext = strchr (pfirst, '/ r'); if (pNext! = null) PNEXT [0] = '/ 0'; m_strmobilename = pfirst;}} catch (.. .) {CloseHandle (m_Overlapped.hEvent); CloseHandle (m_hIDComDev); DeleteCriticalSection (& m_csComm); return (false);} m_hSystemExit = CreateEvent (NULL, TRUE, FALSE, NULL); CreateSubmitPool (m_dwThreadPoolNum); CreateDeliverPool (m_dwThreadPoolNum); CreateShortMsgPool (m_dwSMContentPoolNum); _beginthread ((void (__cdecl *) (void *)) SubmitThreadFun, 0, this); _beginthread ((void (__cdecl *) (void *)) DeliverThreadFun, 0, this); m_bStarted = true; // Outputdebugstring ("START OK."); Return (m_bstarted); bool CGSMPhone :: Close () {SetEvent (m_hSystemExit); Sleep (1200); CloseHandle (m_hSystemExit); CloseHandle (m_Overlapped.hEvent); CloseHandle (m_hIDComDev); DeleteCriticalSection (& m_csComm); FreeSubmitPool (); FreeDeliverPool (); FreeShortMsgPool ( Return (TRUE); Long cgsmphone :: Send (char * pno, char * pmsg, bool BREPORT, BOOL BHANDFREE, BOOL BASYN) {IF (ispened () == false Return (-4); if (pno == null) Return (-5 ); If (pmsg == null) return (-5); if (m_strsmcenter.isempty ()) return (-1); Char szsendbuf [1024] = {0}; char sztemp [20] = {0}; char * preceivedata = null; int LEN = 0; Sprintf (Szsendbuf, "AT CMGS = 60 / R / N); Submit (SzsendBuf, Strlen (SzsendBuf); Memset (SzsendBuf, 0, 1024); DWORD DWRET = Deliver (PreceiveData); if (dwret == 0 || strstr (PreceiveData, ">) == null) {RETURN (-5);} delete [] preceivedata; preceivedata = NULL; Char * p = numberEncode ((char *) (lpctstr) m_strsmcenter; // sprintf (sztemp, "% .2x", strlen (p)); Memcpy (Szsendbuf Len, "0891", 4); // 91 On behalf of the international, ISDN / phone number, there is no need to select other values of Len = 4; IF (Strncmp (p, "68", 2)! = 0) {IF (Strlen (P)! = 12) Return (-5); Memcpy (SzsendBuf Len, "68", 2); LEN = 2 Else {IF (Strlen (P)! = 14) Return (-5);} Memcpy (Szsendbuf LEN, P, STRLEN (P)); LEN = Strlen (P); delete [] P; Memcpy (Szsendbuf Len, "1100", 4); // File header byte, there are many settings, no particular value of Len = 4; Sprintf (SzTemp, "%. 2X", Strlen (PNO)); Memcpy (SzsendBuf Len, Sztemp, 2); LEN = 2; Memcpy (SzsendBuf Len, "81", 2); // Unknown, ISDN / phone number, no need to select other values LEN = 2; P = NumBerencode (PNO); Memcpy (Szsendbuf LEN, P, Strlen (P)); LEN = Strlen (P); delete [] P; If (bhandfree) {// 00 represents the TP_PID value, 18 or 08 represents TP_DCS, A7 represents a short message save 24 hours Memcpy (SzsendBuf Len, "0018A7", 6);} else {MEMCPY (Szsendbuf Len, "0008A7" , 6);} len = 6; DWORD DW = PDUENCODECHN (PMSG, P); Sprintf (SzTemp, "% .2x", DW); Memcpy (Szsendbuf Len, Sztemp, 2); LEN = 2; Memcpy (Szsendbuf LEN, P, DW * 2); LEN = DW * 2; Delete [] P; Szsendbuf [len] = 0x1a; // 1A represents the short message end LEN = 1; Memcpy (SzsendBuf Len, "/ R", 1); LEN = 1; Submit (SzsendBuf, LEN); dwret = Deliver (PreceiveData); if (dwret> 0) {IF (strstr (preceivedata, szsendbuf)! = NULL) {if (m_hwnd! = Null) :: SendMessage (m_hwnd, phone_sms_sub, 0, 0); return (len);} delete [] preceivedata; preceivedata = NULL;} return (0);} long CGSMPhone :: GetShortMsg (SMS_Recv * pSms) {if (m_bStarted == false) return (-1); DWORD dwWaitRet = WaitForMultipleObjects (m_dwSMContentPoolNum, m_phSMPHaveData, FALSE, 1000); if (! dwWaitRet = WAIT_TIMEOUT) {DWORD dwMsgLen = m_pSMPool [dwWaitRet] .dwSize; char * pszBuffer; pszBuffer = new char [dwMsgLen 1]; ZeroMemory (pszBuffer, dwMsgLen 1); CopyMemory (pszBuffer, m_pSMPool [dwWaitRet] .pData, dwMsgLen); delete [] m_pSMPool [dwWaitRet] .pdata; setEvent (m_psmpool [dwwaitret] .hsmpidle; interlockedDecrement (& m_dwsmnumberinpool); INT LEN = 0; char * p = pszbuffer; char sztemp [1024] = {0}; bool beng = false; ZeromeMory (PSMS, SIZEOF (SMS_RECV)); psms-> lmsgtype = msgtype_sms; CopyMemory (SzTemp, P, 2); int nNumlen = ATOI (SzTemp); p = 2; if (nnumlen <= 16) {CopyMemory (psms-> szsmsc, p, nnumlen * 2); NumberDecode (PSMS-> SZSMSC , nnumlen * 2); if (psms-> szsmsc [nnumlen * 2 - 1] == 'f') PSMS-> SZSMSC [nnumlen * 2 - 1] = '/ 0';} P = nnumlen * 2; P = 4; NumberDecode (p, 16); CopyMemory (PSMS-> Szsender, " ", 1); CopyMemory (psms-> szsender 1, p 2, 13); p = 16; IF (Strncmp (p, "0000", 4)) beng = true; p = 4; NumberDecode (P, 10); Sprintf (PSMS-> Sztime, "20% .2S.%. 2S.%. 2S: 2S:%. 2S", P, P 2, P 4, P 6, P 8); p = 10; p = 4; CopyMemory (SzTemp, P, 2); int NMSGLEN = ATOI (SzTemp); P = 2; CHAR * PMSG = NULL; if (beng) {len = pdudecodeEng (p, pmsg);} else {len = pdudecodechn (p, pmsg);} CopyMemory (PSMS-> SZMSG, PMSG, LEN); delete [] pszbuffer; Return (0);} return (-1); long CGSMPhone :: GetShortMsg2 (char * pNo, char * pMsg, char * pTime) {if (m_bStarted == false) return (-1); DWORD dwWaitRet = WaitForMultipleObjects (m_dwSMContentPoolNum, m_phSMPHaveData, FALSE, 1000); if (dwWaitRet! = WAIT_TIMEOUT) {DWORD dwMsgLen = m_pSMPool [dwWaitRet] .dwSize; char * pszBuffer; pszBuffer = new char [dwMsgLen 1]; ZeroMemory (pszBuffer, dwMsgLen 1); CopyMemory (pszBuffer, m_pSMPool [dwWaitRet] .pData, dwMsgLen) Delete [] m_psmpool [dwweitret] .pdata; setEvent (m_psmpool [dwwaitret] .hsmpidle); InterlockedDecrement (& m_dwsmnumberinpool); INT LEN = 0; char * p = pszbuffer; char sztemp [1024] = {0}; bool beng = false; CopyMemory (sztemp, p, 2); int nnumlen = atoi (sztemp); p = nnumlen * 2; p = 6; NumberDecode (P, 16); ZeromeMory (PNO, 15); CopyMemory (PNO, " ", 1); CopyMemory (PNO 1, P 2, 13); P = 18; IF (Strncmp (p, "00", 4) == 0) beng = true; p = 2; NumberDecode (p, 10); ZeromeMory (PTime, 17); Sprintf (PTIME, "20% .2S.%. 2S.%. 2S% .2S:%. 2S", P, P 2, P 4, P 6, P 8); p = 10; p = 4; CopyMemory (SzTemp, P, 2); int NMSGLEN = ATOI (SzTemp); p = 2; char * propult = null; if (beng) {len = pdudecodeEng (p, presult);} else {len = pdudecoden (p , PRESULT;}} {zeromeMory (PMSG, LEN 1); CopyMemory (PMSG, PRESULT, LEN); delete [] PSZBuffer; Return (0);} return; 1 );} long CGSMPhone :: GetMobileName (char * pName) {if (m_strMobileName.IsEmpty ()) {return (-1);} else {ZeroMemory (pName, m_strMobileName.GetLength () 1); CopyMemory (pName, (LPCTSTR) m_strMobileName , m_strmobilename.getlength ()); return (0);}}