http://blog.sina.com.cn/s/blog_494e45fe0100cg4i.html
如何获取PDA/PPC的IMEI/IMSI号码
IMEI(International Mobile Equipment Identity,国际移动身份识别)俗称”串号”存储在手机的EEPROM(俗称码片)里,每一个移动设备都对应一个{wy}的IMEI。
其组成结构为 TAC(6位数字)+FAC(两位数字)+SNR(6位数字)+SP (1位数字)。IMEI{wy}地识别一个移动设备,用于监控被窃或无效的移动设备。
IMSI的全称是International Mobile Subscriber Identification Number,也就是客户识别码。
在GSM系统中,给每个移动用户分配一个{wy}的国际用户识别码IMSI,此码在网中所有位置包括漫游区都是有效的。
下面的类是自己封装的,用来获取IMEI/IMSI号码。
#pragma once
#endif // _MSC_VER > 1000
//#include "resource.h"
#define TAPI_API_LOW_VERSION 0x00010003
#define TAPI_CURRENT_VERSION 0x00020000
#define EXT_API_LOW_VERSION 0x00010000
#define EXT_API_HIGH_VERSION 0x00010000
typedef struct Info
{
char IMSI[128];
char IMEI[128];
}Siminfo;
class SimInfo
{
public:
SimInfo();
virtual ~SimInfo();
static SimInfo Info;
public:
bool Init();
Siminfo GetGeneralInfo();
DWORD m_dwNumDevs;
DWORD m_dwAPIVersion;
HLINEAPP m_hLineApp;
HLINE m_hLine;
DWORD m_dwExtVersion;
DWORD m_dwTSPILineDeviceID;
LPTSTR g_dwImei;
private:
void GetTAPIErrorMsg(TCHAR *szMsg,int nSize, DWORD dwError);
DWORD GetTSPLineDeviceID(const TCHAR* const psTSPLineName);
};
#endif // !defined(AFX_IMEI1_H__84CB8CFD_9DA9_470E_867E_2D689F916CBE__INCLUDED_)
// DevInfo.cpp: implementation of the DevInfo class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
//#include "imei.h"
#include "DevInfo.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DevInfo::DevInfo()
{
m_dwAPIVersion = TAPI_CURRENT_VERSION;
m_hLineApp = 0;
m_hLine = 0;
m_dwExtVersion = 0;
}
DevInfo::~DevInfo()
{
}
bool DevInfo::Init()
{
// set the line init params
LINEINITIALIZEEXPARAMS LineExtParams;
LineExtParams.dwTotalSize = sizeof(LineExtParams);
LineExtParams.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;
if (::lineInitializeEx(&m_hLineApp, 0, 0, _T("Developer.com Test"),
&m_dwNumDevs, &m_dwAPIVersion, &LineExtParams))
{
//EndDialog(IDOK);
return false;
}
m_dwTSPILineDeviceID = GetTSPLineDeviceID(CELLTSP_LINENAME_STRING);
//m_dwTSPILineDeviceID = GetTSPLineDeviceID(L"GPRS Modem - Data Port as COM7:");
if ( m_dwTSPILineDeviceID == (DWORD)-1 )
{
::lineShutdown(m_hLineApp);
//EndDialog(IDOK);
return false;
}
// open the line
if( ::lineOpen(m_hLineApp, m_dwTSPILineDeviceID,
&m_hLine, m_dwAPIVersion, 0, 0,
LINECALLPRIVILEGE_OWNER, LINEMEDIAMODE_DATAMODEM, 0) )
{
::lineShutdown(m_hLineApp);
//EndDialog(IDOK);
return false;
}
// set up ExTAPI
if ( ::lineNegotiateExtVersion(m_hLineApp, m_dwTSPILineDeviceID,
m_dwAPIVersion, EXT_API_LOW_VERSION,
EXT_API_HIGH_VERSION, &m_dwExtVersion) )
{
::lineClose(m_hLine);
::lineShutdown(m_hLineApp);
//EndDialog(IDOK);
return false;
}
return true;
}
DWORD DevInfo::GetTSPLineDeviceID(const TCHAR *const psTSPLineName)
{
DWORD dwReturn = -1;
for(DWORD dwCurrentDevID = 0 ; dwCurrentDevID < m_dwNumDevs ; dwCurrentDevID++)
{
LINEEXTENSIONID LineExtensionID;
if( ::lineNegotiateAPIVersion(m_hLineApp, dwCurrentDevID,
TAPI_API_LOW_VERSION, TAPI_CURRENT_VERSION,
&m_dwAPIVersion, &LineExtensionID) == 0 )
{
LINEDEVCAPS LineDevCaps;
LineDevCaps.dwTotalSize = sizeof(LineDevCaps);
if( ::lineGetDevCaps(m_hLineApp, dwCurrentDevID,
m_dwAPIVersion, 0, &LineDevCaps) == 0 )
{
BYTE* pLineDevCapsBytes = new BYTE[LineDevCaps.dwNeededSize];
if(0 != pLineDevCapsBytes)
{