In this article I am placing the code and sample to retrieve IMEI and IMSI number by using OpennetCF Tapi which is free now. 1) Start the new Windows Mobile Project 2) Right click on References --> Select Broswe --> Select the TapiLib.dll 3) Add the class file and name ImeiNum and place the follwing code
class ImeiNum
{ //Import cellcore.dll [DllImport("cellcore.dll")] internal static extern int lineGetGeneralInfo(IntPtr hLine, byte[] bCache);
// code to get IMEI private static string getIMEIInfo()
{ string IMEI;Tapi t = new Tapi();
t.Initialize(); Line _line = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, LINECALLPRIVILEGE.MONITOR); byte[] buffer = new byte[512];
//write size BitConverter.GetBytes(512).CopyTo(buffer, 0);if (lineGetGeneralInfo(_line.hLine, buffer) != 0)
{ throw newSystem.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error(),"TAPI Error: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString("X"));
} int serialsize = BitConverter.ToInt32(buffer, 36); int serialoffset = BitConverter.ToInt32(buffer, 40);
IMEI = System.Text.Encoding.Unicode.GetString(buffer, serialoffset, serialsize);IMEI = IMEI.Substring(0, IMEI.IndexOf( Convert.ToChar(0)));
_line.Dispose(); t.Shutdown();
return IMEI;
} }
4) Add another class and name it to ImsiNum. Place the following code in this class
public struct GeneralInfo
{ public string Manufacturer;
public string Model; public string Revision;
public string SerialNumber; public string SubscriberNumber;
} class ImsiNum
{
[DllImport("cellcore.dll")]private static extern int lineGetGeneralInfo(IntPtr hLigne, byte[] lpLineGeneralInfo);
public static GeneralInfo GetGeneralInfo(Line l)
{ GeneralInfo lgi = new GeneralInfo(); byte[] buffer = new byte[512];
BitConverter.GetBytes(512).CopyTo(buffer, 0); if (lineGetGeneralInfo(l.hLine, buffer) != 0)
{ throw newSystem.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error(),"TAPI Error: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString("X"));
} int subscsize = BitConverter.ToInt32(buffer, 44);
int subscoffset = BitConverter.ToInt32(buffer, 48);lgi.SubscriberNumber = System.Text. Encoding.Unicode.GetString(buffer, subscoffset, subscsize).ToString();
lgi.SubscriberNumber = lgi.SubscriberNumber.Replace("\0", ""); return lgi;
}
public static string GetIMSINumber()
{ string result = "";
try
{ Tapi t = new Tapi();
t.Initialize(); Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
GeneralInfo gi = GetGeneralInfo(l);
result = gi.SubscriberNumber; l.Dispose(); t.Shutdown(); } catch// (Exception ex)
{ result = "";
} return result;
}
}
|
doesn´t working!