最近在忙一个移动警务的项目,需要获取SIM卡的信息,来做身份的验证。考虑到获取:国际移动设备识别码(IMEI:International Mobile Equipment Identification Number)和国际移动用户识别码(IMSI:International Mobile Subscriber Identification Number),读取这两个号码用到TAPI的lineGetGeneralInfo()函。在新版的OpenNetCF里没有发现对这个函数的封装(也许我没找到),于是到网上找了找,找到一个以前版本OpenNetCF里的:TapiLib.dll,包含对Windows ce phone api 的封装(TAPI),综合网上的一些资料,实现代码如下:

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

/// <summary>
    /// Tapi控制类
    /// </summary>
    public class ControlTapi
    {
[DllImport("cellcore.dll")]
        private static extern int lineGetGeneralInfo(IntPtr hLigne,byte[]lpLineGeneralInfo );
/// <summary>
        /// 调用cellcore.dll获取sim卡的综合信息
        /// </summary>
        /// <param name="l"></param>
        /// <returns></returns>
        private  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 new System.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;
}
/// <summary>
        /// 获取sim卡的IMSI
        /// </summary>
        /// <returns></returns>
        public static string  GetIMSINumber()
        {
            string result = "";
            try
            {
                Tapi t = new Tapi();
                t.Initialize();
                Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
                ControlTapi ctapi = new ControlTapi();
                GeneralInfo gi = ctapi.GetGeneralInfo(l);
              
                result =  gi.SubscriberNumber;
                l.Dispose();
                t.Shutdown();
}
            catch// (Exception ex)
            {
                result = "";
            }
return result;
}
/// <summary>
        /// 获取IMEI的号码
        /// </summary>
        /// <returns></returns>
        public static string GetIMEINumber()
        {
            string result = "";
            try
            {
                Tapi t = new Tapi();
                t.Initialize();
                Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
                ControlTapi ctapi = new ControlTapi();
                GeneralInfo gi = ctapi.GetGeneralInfo(l);
                result = gi.SerialNumber;
                l.Dispose();
                t.Shutdown();
}
            catch// (Exception ex)
            {
                result = "";
            }
return result;
        }

    }

vb 的代码你可以去看看这里:http://www.peterfoot.net/RetrieveIMEIThroughTAPI.aspx

另:
1、环境:在vs2005+windows mobile 5.0 +多普达818测试通过。
2、
关于获取SIM卡的本机号码,你可以用:http://www.microsoft.com/china/msdn/archives/library/dnnetcomp/html/netcfPhoneAPI.asp,这里 提供的方法,不过这个方法需要安全认证,比较麻烦,具体认证的方式见:http://www.microsoft.com/china/MSDN/library/Mobility/pocketpc/2k3smartphonesecurity.mspx?pf=true。
3、TapiLib.dll的下载地址:http://www.cnblogs.com/Files/xjb/TapiLib.rar
4、参考资料:
http://hucgy.bokee.com/3328836.html

转载于:https://www.cnblogs.com/wuwuwu/archive/2007/02/07/6163117.html

Windows mobile 下读取手机SIM卡信息相关推荐

  1. 实测Windows Mobile下卡巴斯基手机安全软件表现

    实测Windows Mobile下卡巴斯基手机安全软件表现 文/ 图 鲜橙加冰(王文文) [51CTO.com 独家特稿]随着科技的不断发展和3G技术的不断成熟,我国正迅速进入一个全新的3G时代.大量 ...

  2. Android开发之获取手机SIM卡信息

    TelephonyManager是一个管理手机通话状态.电话网络信息的服务类,该类提供了大量的getXxx(),方法获取电话网络的相关信息. TelephonyManager类概述: 可用于访问有关设 ...

  3. 双卡android手机SIM卡信息探索 ,获取手机 SIM卡数量和SIM卡id、iccid

    废话不多,直接上干货==> 1 以下所有方法都需要在AndroidManifest.xml声明权限 <uses-permission android:name="android. ...

  4. android获取手机sim卡信息,Android获取手机SIM卡运营商信息的方法

    本文实例讲述了Android获取手机SIM卡运营商信息的方法,对于Android程序设计有非常实用的价值.分享给大家供大家参考之用.具体方法如下: 主要功能代码如下: /** * 获取SIM卡运营商 ...

  5. cordova插件 - 获取手机SIM卡信息(包括手机号)

    插件名称:cordova-plugin-sim 地址:https://www.npmjs.com/package/cordova-plugin-sim 说明:这个插件可以从sim卡中,获取 carri ...

  6. sim卡没坏但苹果手机无服务_手机资讯:苹果iPhone读取不Sim卡怎么办

    如今使用IT数码设备的小伙伴们是越来越多了,那么IT数码设备当中是有很多知识的,这些知识很多小伙伴一般都是不知道的,就好比最近就有很多小伙伴们想要知道苹果iPhone读取不Sim卡怎么办,那么既然现在 ...

  7. Android 读取手机SD卡根目录下某个txt文件的文件内容

    1.先看activity_main.xml文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/and ...

  8. 手机SIM卡的详细介绍

    什么是SIM卡 移动话机与SIM卡共同构成移动通信终端设备.无论是GSM系统还是CDMA系统,数字移动电话机用户在"入网"时会得到一张SIM卡(CDMA叫UIM卡).SIM卡是(S ...

  9. Windows Mobile下GPS管理软件NavsGo之GPS侦测功能的开发

    简述 在上篇文章 Windows Mobile下GPS管理软件NavsGo之GPS监控功能的开发 概述了NavsGo项目以及讲述了GPS监控功能的开发,GPS.net控件的使用,这篇文章讲述侦测功能的 ...

最新文章

  1. DD来拜年送红包啦!
  2. go-zero:微服务框架
  3. CUDA全局变量(__device__)的初始化与使用:cudaMemoryToSymbol、cudaMemoryFromSymbol、cudaGetSymbolAddress
  4. mysql丢失一条事务_SpringBoot之MySQL数据的丢失的元凶--事务(转)
  5. 《构建之法》读书心得
  6. ECharts(Enterprise Charts 商业产品图表库)初识
  7. 用友中标:打造新一代云化ERP 落地大型企业互联网+
  8. linux生成密钥公钥,linux 生成密钥和公钥,实现免密登录
  9. stack(后进先出)
  10. 软考-高项-论文-信息系统项目的进度管理
  11. 云计算机到底是啥来的,啥叫云计算(云计算究竟是什么)
  12. 机器学习深版11:HMM模型
  13. mysql触发器优缺点_MySQL 的触发器
  14. 刚体6D位姿估计方法综述
  15. 【第七章】 对JDBC的支持 之 7.1 概述 ——跟我学spring3
  16. matlab 求旁瓣,主瓣、栅瓣和旁瓣(MATLAB源代码 解释)
  17. ubuntu18qt报错:The process was ended forcefully.
  18. AI2021下载Illustrator2021最新下载AI最新下载安装1分钟看完就会
  19. BIGEMAP GIS Designer地图下载器详细功能列表
  20. 决定成败的49个细节

热门文章

  1. 让元素固定_49种元素对钢铁性能的影响
  2. 唯一的超级语言,前进的步伐不可阻挡
  3. Linux 3.13.0删除了Netlink API函数genl_register_ops() / genl_unregister_ops()
  4. Storyboard和Xib混用黑魔法-swift版
  5. Unity编辑器定制和开发插件
  6. 游戏开发经验分享:我所理解的打击感
  7. C#实现TreeView向XML的绝对转换类
  8. linux做伪分布时ip设置,Linux下伪分布模式的Hadoop部署
  9. 【java学习之路】(java框架)008.JdbcTemplate
  10. mysql基线检查_Mysql安全基线检查