Programmatically read SIM contacts of windows mobile smart phone 5.0 and Pocket PC !! below is the sample code which is in C# after a rigorous search on internet i got this sample code so thought of posting it here...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace DeviceApplication33
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private const Int64 S_OK = 0x00000000;
public const int SIM_CAPSTYPE_ALL = 0x3F; //
public const int SIM_PBSTORAGE_SIM = 0x10; //
public const int SIM_SMSSTORAGE_SIM = 0x2; //
[StructLayout(LayoutKind.Sequential)]
public struct SIMPHONEBOOKENTRY
{
public uint cbSize; //
public uint dwParams; //
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string lpszAddress; //
public uint dwAddressType; //
public uint dwNumPlan; //
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string lpszText; //
}
[DllImport("cellcore.dll")]
public static extern int SimInitialize(uint dwFlags,
int lpfnCallBack, uint dwParam, ref int lphSim);
[DllImport("cellcore.dll")]
public static extern int SimGetPhonebookStatus(int hSim,
uint dwLocation, ref uint lpdwUsed, ref uint lpdwTotal);
[DllImport("cellcore.dll")]
public static extern int SimReadPhonebookEntry(int hSim, uint dwLocation, uint dwIndex, ref SIMPHONEBOOKENTRY entry);
[DllImport("cellcore.dll", SetLastError = true)]
public static extern int SimDeinitialize(int hSim);
public static List GetSIMContactList()
{
int hSim = 0;
List list = new List();
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 string[2] { entry.lpszText.Trim(), entry.lpszAddress.Trim() });
}
return list;
}
catch
{
throw;
}
finally
{
SimDeinitialize(hSim);
}
}
private void Form1_Load(object sender, EventArgs e)
{}
}
}
if you know much better way or want to say something you can reach me via mail clickhere
Search
Monday, September 15, 2008
How to read SIM Contacts of Windows Mobile
Posted by
Manjunath
at
11:43 PM
Labels: programming
Subscribe to:
Post Comments (Atom)
1 comments:
Thanks for sharing
Post a Comment