Synchronize Windows Mobile SIM card text messages

Source: Internet
Author: User

Synchronize Windows Mobile SIM card text messages

Author: Jin haijian

Background:By default, SMS messages in the SIM card are synchronized to the SMS database of the system. The supervisor will delete the record with the sim SMS flag in the database and then import new content from the SIM card. Because the project does not allow cprog.exe to run, the text message import can only be handled by your own program.

Content:Sim API, cemapi, CEDB

Difficulties:When operating SIM card text messages on the SMS interface, we can directly Delete and copy SIM messages. In terms of the delete action, two operations are actually performed: Read the index stored on the SIM card from the SMS database, and then call simdeletemessage to delete the sim message. After the SIM card text message is deleted, the system deletes the content in the database. Therefore, a SIM card text message must also delete records from data and SIM card records. Then the problem arises. How does the system know that it is a SIM card text message, and how does it know its index on the SIM card. When we copy the text message, we call simreadmessage. If we can read the text message, we will know its index on the SIM card. We need to store the entire index number in the SMS database. In Windows Mobile, we can use cemapi to operate on text messages. Use iMessage to print the record content of each SIM card text message, and then perform a careful comparison and analysis to find out the following differences:

Sim SMS flag: The pr_message_class field, which can be found in mapitags. h. Use "IPM. smstext" to represent a common text message, and use "IPM. smstext. Sim" to indicate a SIM card text message.

SIM card text message index: the pr_smsstorage_id field, which is not defined by Microsoft and found by comparison. Use the macro below to define

# Define pr_smsstorage_id prop_tag (pt_long, 0x825c)

Implementation:Through the above analysis, it is easy to implement with code, and the sim API and cemapi cannot be called. The Code is as follows (the code is incomplete, but an important part is posted)

Hresultimportsimsms () <br/>{< br/> hresult hR = s_false; <br/> ccomptr <imapisession> spsession; <br/> ccomptr <imsgstore> spmsgstore; <br/> ccomptr <imapifolder> spfolder; </P> <p> // logon to mapi <br/> hR = mapilogonex (0, null, null, 0, & spsession); <br/> CHR (HR); </P> <p> hsimhsim = NULL; <br/> DWORD dwusedcount = 0; <br/> dworddwused = 0, dwtotal = 0; <br/> If (failed (siminitialize (null, null, 0, & hsim) <br/> goto error; </P> <p> If (failed (simgetsmsstoragestatus (hsim, sim_smsstorage_sim, & dwused, & dwtotal) <br/> goto error; </P> <p> hR = getsmsgstore (spsession, spmsgstore); <br/> CHR (HR); </P> <p> hR = getsmsfolder (spmsgstore, spfolder, pr_ce_ipm_inbox_entryid); <br/> CHR (HR); </P> <p> for (INT I = 1; I <= dwtotal; I ++) <br/>{< br/> If (dwusedcount> = dwused) <br/> break; <br/> simmessage simmsg = {0 }; <br/> If (s_ OK = simreadmessage (hsim, sim_smsstorage_sim, I, & simmsg) <br/>{< br/> dwusedcount ++; <br/> createsms (spfolder, simmsg. lpszaddress, simmsg. lpszmessage, simmsg. streceivetime, I); <br/>}< br/> error: <br/> If (hsim) <br/> simdeinitialize (hsim ); <br/> return hr; <br/>}< br/>

 

Hresult createsms (imapifolder * spfloder, lpctstr lpszaddress, lpctstr pszmessage, <br/> systemtime completed IME, DWORD dwmsgindex) <br/>{< br/> hresult hR = s_ OK; <br/> lpmessage pmessage = NULL; <br/> hR = spfloder-> createmessage (null, 0, & pmessage ); </P> <p> If (failed (HR) <br/> {<br/> return hr; <br/>}</P> <p> // now we set the additional properties for the <br/> // message <br/> spropvalue props [8]; <br/> zeromemory (& props, sizeof (props )); </P> <p> // first set the subject of the message <br/> // as the SMS we are going to send <br/> props [0]. ulproptag = pr_subject; <br/> props [0]. value. lpszw = (lpwstr) pszmessage; </P> <p> props [1]. ulproptag = pr_sender_email_address; <br/> props [1]. value. lpszw = (lpwstr) lpszaddress; </P> <p> props [2]. ulproptag = pr_sender_name; <br/> props [2]. value. lpszw = (lpwstr) lpszaddress; </P> <p> props [3]. ulproptag = pr_message_flags; <br/> props [3]. value. ul = msgflag_read; </P> <p> props [4]. ulproptag = pr_message_delivery_time; <br/> systemtimetofiletime (& systime, & props [4]. value. ft); </P> <p> props [5]. ulproptag = pr_message_class; <br/> props [5]. value. lpszw = (lpwstr) l "IPM. smstext. sim "; </P> <p> props [6]. ulproptag = pr_message_size; <br/> props [6]. value. L = (wcslen (pszmessage) + 1) * sizeof (tchar); </P> <p> props [7]. ulproptag = pr_smsstorage_id; <br/> props [7]. value. ul = dwmsgindex; </P> <p> If (usimid <= 2) <br/> {<br/> hR = pmessage-> setprops (sizeof (props) /sizeof (props [0]), (lpspropvalue) & props, null ); <br/>}< br/> else <br/> {<br/> hR = pmessage-> setprops (sizeof (props)/sizeof (props [0]) -1, (lpspropvalue) & props, null); <br/>}< br/> pmessage-> savechanges (0 ); </P> <p> pmessage-> release (); </P> <p> return hr; <br/>}< br/>

The next article explains how to synchronize SIM card contacts.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.