to read the IMEI in Compact .NET

//Import cellcore.dll

[DllImport("cellcore.dll")]
 internal static extern int lineGetGeneralInfo(IntPtr hLine, byte[] bCache);

// code to get IMEI
private void 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 new System.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)));

AppSettings.SetIMEI(IMEI);
_line.Dispose();
t.Shutdown();
}

To get the TAPILib: http://www.alexfeinman.com/download.asp?doc=tapi1.1.zip

Comments

Leave a Reply