⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 It is useful to get Mobile IMEI Number of a Windows Mobie Programmatically
💻 CS
字号:

//
// Ported from Peter Foot's VB TAPI example, based on Alex Feinman's TAPI wrapper
//
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 TapiCSExample
{
    public partial class Form1 : Form
    {
        [DllImport("cellcore.dll")]
        private static extern int lineGetGeneralInfo(IntPtr hLine, byte[] lpLineGeneralInfo);

        public Form1()
        {
            InitializeComponent();
        }

        private void btnGetInfo_Click(object sender, EventArgs e)
        {
            OpenNETCF.Tapi.Tapi objTapi = new OpenNETCF.Tapi.Tapi();

            objTapi.Initialize();

            OpenNETCF.Tapi.Line objLine = objTapi.CreateLine(0, OpenNETCF.Tapi.LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);

            try
            {
                GeneralInfo objGI = GetGeneralInfo(objLine);

                lblManufacturer.Text = objGI.Manufacturer;
                lblModel.Text = objGI.Model;
                lblRevision.Text = objGI.Revision;
                lblSubscriber.Text = objGI.SubscriberNumber;
                lblImei.Text = objGI.SerialNumber;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            objLine.Dispose();
            objTapi.Shutdown();
        }

        private GeneralInfo GetGeneralInfo(OpenNETCF.Tapi.Line objLine) 
        {
            GeneralInfo objGI;

            byte[] arrBuffer = new byte[512];
            BitConverter.GetBytes(512).CopyTo(arrBuffer, 0);

            int iStatus;
            if( (iStatus = lineGetGeneralInfo(objLine.hLine, arrBuffer)) != 0)
            {
                throw new System.ComponentModel.Win32Exception(
                    System.Runtime.InteropServices.Marshal.GetLastWin32Error(),
                    "TAPI Error: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString("X")
                );
            }

            int iManusize = BitConverter.ToInt32(arrBuffer, 12);
            int iManuoffset = BitConverter.ToInt32(arrBuffer, 16);
            objGI.Manufacturer = System.Text.Encoding.Unicode.GetString(arrBuffer, iManuoffset, iManusize);
            objGI.Manufacturer = objGI.Manufacturer.Substring(0, objGI.Manufacturer.IndexOf('\0'));

            int iModelsize = BitConverter.ToInt32(arrBuffer, 20);
            int iModeloffset = BitConverter.ToInt32(arrBuffer, 24);
            objGI.Model = System.Text.Encoding.Unicode.GetString(arrBuffer, iModeloffset, iModelsize);
            objGI.Model = objGI.Model.Substring(0, objGI.Model.IndexOf('\0'));

            int iRevsize  = BitConverter.ToInt32(arrBuffer, 28);
            int iRevoffset = BitConverter.ToInt32(arrBuffer, 32);
            objGI.Revision = System.Text.Encoding.Unicode.GetString(arrBuffer, iRevoffset, iRevsize);
            objGI.Revision = objGI.Revision.Substring(0, objGI.Revision.IndexOf('\0'));

            int iSerialsize = BitConverter.ToInt32(arrBuffer, 36);
            int iSerialoffset = BitConverter.ToInt32(arrBuffer, 40);
            objGI.SerialNumber = System.Text.Encoding.Unicode.GetString(arrBuffer, iSerialoffset, iSerialsize);
            objGI.SerialNumber = objGI.SerialNumber.Substring(0, objGI.SerialNumber.IndexOf('\0'));

            int iSubscsize = BitConverter.ToInt32(arrBuffer, 44);
            int iSubscoffset = BitConverter.ToInt32(arrBuffer, 48);
            objGI.SubscriberNumber = System.Text.Encoding.Unicode.GetString(arrBuffer, iSubscoffset, iSubscsize);
            objGI.SubscriberNumber = objGI.SubscriberNumber.Substring(0, objGI.SubscriberNumber.IndexOf('\0'));

            return objGI;
        }

        public struct GeneralInfo
        {
            public string Manufacturer;
            public string Model;
            public string Revision;
            public string SerialNumber;
            public string SubscriberNumber;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -