软件获取imei和imsi_获取手机的IMEI与IMSI

一.原理

使用了Pocket PC SDK的EXTAPI

实现过程如下:

1.首先加如头文件:

#include "tapi.h"

#include "extapi.h"

#define TAPI_API_HIGH_VERSION   0x00020000

#define EXT_API_LOW_VERSION     0x00010000

#define EXT_API_HIGH_VERSION    0x00010000

2.引入库文件cellcore.lib

3.输入代码即可:

BOOL GetDeviceSIMInfo(CString &strIMEI,CString &strIMSI)

{

BOOL bSus = FALSE;                  //返回结果是否正确

TCHAR szIMEI[MAX_PATH];             //保存设备的IMEI

TCHAR szIMSI[MAX_PATH];             //保存设备的IMSI

//初始化数组

memset(szIMEI,0,sizeof(strIMEI));

memset(szIMSI,0,sizeof(szIMSI));

LINEGENERALINFO *lineGeneralInfo;   //保存设备序列号的信息的结构体

HLINEAPP hLineApp = 0;

HLINE hLine = 0;

DWORD dwNumDevs;

DWORD dwAPIVersion = TAPI_API_HIGH_VERSION;

DWORD dwExtVersion = 0;

DWORD dwDeviceID;

DWORD dwMediaMode = LINEMEDIAMODE_DATAMODEM | LINEMEDIAMODE_INTERACTIVEVOICE;

LONG tapiresult;

DWORD temp;

LINEINITIALIZEEXPARAMS lineInitializeExParams;

lineGeneralInfo = (LINEGENERALINFO*)malloc(1024);

lineGeneralInfo->dwTotalSize = sizeof(LINEGENERALINFO);

lineInitializeExParams.dwTotalSize = sizeof(lineInitializeExParams);

lineInitializeExParams.dwOptions =  LINEINITIALIZEEXOPTION_USEEVENT; //The application desires to use the Event Handle event notification mechanism

tapiresult = lineInitializeEx(&hLineApp, 0, 0,L"SimTry", &dwNumDevs, &dwAPIVersion,&lineInitializeExParams); //returns 0 (SUCCESS)

lineGeneralInfo = (LINEGENERALINFO*)malloc(sizeof(LINEGENERALINFO));

lineGeneralInfo->dwTotalSize = sizeof(LINEGENERALINFO);

for (dwDeviceID = 0; dwDeviceID < dwNumDevs;dwDeviceID++)

{

tapiresult = lineNegotiateExtVersion(hLineApp, dwDeviceID, dwAPIVersion, EXT_API_LOW_VERSION,

EXT_API_HIGH_VERSION, &dwExtVersion);               //returns 0 (SUCCESS)

tapiresult = lineOpen(hLineApp, dwDeviceID,&hLine, dwAPIVersion, 0, 0,

LINECALLPRIVILEGE_OWNER, dwMediaMode, 0);           //returns 0 (SUCCESS)

tapiresult = lineGetGeneralInfo(hLine, lineGeneralInfo); //returns 0 (SUCCESS)

if((tapiresult == 0) && (lineGeneralInfo->dwNeededSize > lineGeneralInfo->dwTotalSize))

{

//重新获取最新的值

temp = lineGeneralInfo->dwNeededSize;

free(lineGeneralInfo);

lineGeneralInfo = (LINEGENERALINFO*)malloc(temp);

lineGeneralInfo->dwTotalSize = temp;

tapiresult = lineGetGeneralInfo(hLine, lineGeneralInfo);

//已将结果拿到

//IMEI

lstrcpy(szIMEI, (TCHAR*)((char*)lineGeneralInfo

+ lineGeneralInfo->dwSerialNumberOffset));

//IMSI

if(lineGeneralInfo->dwSubscriberNumberSize > 2)

{

for(int j=0;jdwSubscriberNumberSize/2;j++)

szIMSI[j] = *((unsigned short *)(lineGeneralInfo) + j + lineGeneralInfo->dwSubscriberNumberOffset/2);

}

bSus = TRUE;

break;

}

}

if(bSus)

{

strIMEI = CString(szIMEI);

strIMSI = CString(szIMSI);

}

//回收资源

free(lineGeneralInfo);

if(hLine)

lineClose(hLine);

if(hLineApp)

lineShutdown(hLineApp);

return bSus;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值