Read the database to get the mobile phone contact

Source: Internet
Author: User

To obtain contacts on mobile phones, Microsoft provides the icontact interface, which can be used to obtain SIM card contacts, which can be achieved through the simreadphonebookentry function. Examples are provided in the SDK. However, you can also read contacts by reading the database.

I remember that I have seen on the Internet the efficiency of using the icontact interface to read contacts and reading databases to get contacts. It seems that reading databases can be much faster.

Mobile phone contacts are stored in Pim. on the vol volume, the database name is contacts database. I don't know when the SIM card contact will be stored in this database, so if I want to obtain all contacts, read-Only databases can be used to increase the reading speed, especially when reading SIM cards.

After opening the database, obtain the number of contacts in the database, apply for a space, and read the contacts one by one.

 

The following code is used:

  1. Int getcontactbyedb ()
  2. {
  3. Ceguid guid = {0 };
  4. Create_invalidguid (& guid );
  5. If (! Cemountdbvolex (& guid, _ T ("Pim. Vol"), null, open_existing | edb_mount_flag ))
  6. {
  7. Return-1;
  8. }
  9. Ceoid OID = 0;
  10. Handle hdatabase = ceopendatabaseinsession (null, & guid, & OID,
  11. _ T ("Contacts Database"), null,
  12. Cedb_autoincrement, null );
  13. If (hdatabase = invalid_handle_value)
  14. {
  15. Ceunmountdbvol (& guid );
  16. Return-1;
  17. }
  18. // Obtain the number of contacts
  19. By_handle_db_information bhdi = {0 };
  20. Bhdi. wversion = 2;
  21. Bhdi. guidvol = guid;
  22. Bhdi. oiddbase = OID;
  23. If (! Cegetdbinformationbyhandle (hdatabase, & bhdi ))
  24. {
  25. Return-1;
  26. }
  27. DWORD dwcontactnumber = bhdi. infdatabase. dwnumrecords;
  28. * Ppuinfo = new phoneuserinfo [dwcontactnumber];
  29. If (* ppuinfo = NULL)
  30. {
  31. Return-1;
  32. }
  33. // Start reading
  34. Word wnumprops = 0;
  35. Cepropval * precord = NULL;
  36. DWORD dwbufsize = 0;
  37. Ceoid oidrecord = 0;
  38. DWORD dwpos = 0;
  39. Ceseekdatabaseex (hdatabase, cedb_seek_beginning, 0, 0, 0 );
  40. While (oidrecord = cereadrecordpropsex (hdatabase, cedb_allowrealloc, & wnumprops, null, (lpbyte *) & precord, & dwbufsize, null ))
  41. {
  42. For (INT I = 0; I <wnumprops; I ++)
  43. {
  44. Switch (precord [I]. propid)
  45. {
  46. Case pimpr_first_name:
  47. Break;
  48. Case pimpr_last_name:
  49. Break;
  50. Case pimpr_mobile_telephone_number: // mobile phone number (this is also the field read by the SIM card)
  51. Break;
  52. }
  53. }
  54. Dwpos ++;
  55. }
  56. Closehandle (hdatabase );
  57. Ceunmountdbvol (& guid );
  58. Return dwpos;
  59. }

Some people say that it is not successful to use cegetdbinformationbyhandle to retrieve database records. During the test, it is normal and the number of records can be correctly obtained.

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.