Read SIM card information of mobile phone in Windows Mobile

Source: Internet
Author: User
Recently, I am working on a mobile police project. I need to obtain SIM card information for identity verification. Considering the acquisition of the international mobile device identification code (IMEI: International Mobile Equipment identification number) and the International Mobile User identification code (imsi: International Mobile Subscriber identification number ), the linegetgeneralinfo () function of TAPI is used to read the two numbers. In the new version of opennetcf, I did not find the encapsulation of this function (maybe I did not find it), So I went online and found the tapilib in the previous version of opennetcf. DLL, including the encapsulation of Windows CE phone API (TAPI), based on some information on the Internet Code As follows:

Public struct generalinfo
{
Public String manufacturer;
Public String Model;
Public String revision;
Public String serialnumber;
Public String subscribernumber;
} // <Summary>
/// TAPI control class
/// </Summary>
Public class controltapi
{[Dllimport ("cellcore. dll")]
Private Static extern int linegetgeneralinfo (intptr hligne, byte [] lplinegeneralinfo); // <summary>
/// Call cellcore. DLL to obtain the integrated SIM card information
/// </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>
/// Obtain the imsi of the SIM card
/// </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>
/// Obtain the IMEI number
/// </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 code you can go here: http://www.peterfoot.net/RetrieveIMEIThroughTAPI.aspx

In addition:
1. Environment: The test passed in vs2005 + Windows Mobile 5.0 + 818.
2,
On the acquisition of SIM card of the local number, you can use: token provided by the method, but this method requires security authentication, more trouble, the specific authentication method see: 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. References:
Http://hucgy.bokee.com/3328836.html

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.