怎样获取IMSI


BOOLGetDeviceSIMInfo(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;j dwSubscriberNumberSize/2;j++)
szIMSI[j] = *((unsigned short *)(lineGeneralInfo) + j + lineGeneralInfo->dwSubscriberNumberOffset/2);

}

bSus = TRUE;
break;
}
}

if(bSus)
{
this->strIMEI = CString(szIMEI);
this->strIMSI = CString(szIMSI);

strIMEI = CString(szIMEI);
strIMSI = CString(szIMSI);
}
//AfxMessageBox(strIMEI);
//AfxMessageBox(strIMSI);

//回收资源
free(lineGeneralInfo);
if(hLine)
lineClose(hLine);
if(hLineApp)
lineShutdown(hLineApp);

return bSus;
}

你可能感兴趣的:(怎样获取IMSI)