public List<ContactNumber> GetSimContacts() { int hSim = 0; var list = new List<ContactNumber>(); try { int result = SimInitialize(0, 0, 0, ref hSim); if (result != 0) throw new Exception("SIM Contacts"); uint uiUsed = 0; uint uiTotal = 0; result = SimGetPhonebookStatus(hSim, SIM_PBSTORAGE_SIM, ref uiUsed, ref uiTotal); for (int i = 1; i <= uiUsed; i++) { SIMPHONEBOOKENTRY entry = new SIMPHONEBOOKENTRY(); entry.cbSize = (uint)Marshal.SizeOf(typeof(SIMPHONEBOOKENTRY)); result = SimReadPhonebookEntry(hSim, SIM_PBSTORAGE_SIM, (uint)i, ref entry); list.Add(new ContactNumber() { Name = entry.lpszText, Number = entry.lpszAddress }); } return list; } finally { SimDeinitialize(hSim); } }
public static extern int SimReadPhonebookEntry(int hSim, uint dwLocation, uint dwIndex, ref SIMPHONEBOOKENTRY entry);