📄 imsidlg.cpp
字号:
// IMSIDlg.cpp : implementation file
//
#include "stdafx.h"
#include "IMSI.h"
#include "IMSIDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CIMSIDlg dialog
CIMSIDlg::CIMSIDlg(CWnd* pParent /*=NULL*/)
: CDialog(CIMSIDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CIMSIDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CIMSIDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CIMSIDlg::OnBnClickedButton1)
END_MESSAGE_MAP()
// CIMSIDlg message handlers
BOOL CIMSIDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CIMSIDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
DRA::RelayoutDialog(
AfxGetInstanceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_IMSI_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_IMSI_DIALOG));
}
#endif
DWORD CIMSIDlg::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)
{
LINEDEVCAPS* pLineDevCaps = (LINEDEVCAPS*)pLineDevCapsBytes;
pLineDevCaps->dwTotalSize = LineDevCaps.dwNeededSize;
if( ::lineGetDevCaps(m_hLineApp, dwCurrentDevID,
m_dwAPIVersion, 0, pLineDevCaps) == 0 )
{
if(0 == _tcscmp((TCHAR*)((BYTE*)pLineDevCaps+pLineDevCaps->dwLineNameOffset),
psTSPLineName))
{
dwReturn = dwCurrentDevID;
}
}
delete[] pLineDevCapsBytes;
}
}
}
}
return dwReturn;
}
BOOL CIMSIDlg::GetHWInfo(MyGeneralInfo& mygenralinfo)
{
// set the line init params
LINEINITIALIZEEXPARAMS LineExtParams;
LineExtParams.dwTotalSize = sizeof(LineExtParams);
LineExtParams.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;
m_dwAPIVersion = TAPI_CURRENT_VERSION;
if (::lineInitializeEx(&m_hLineApp, 0, 0, _T("Developer.com Test"),
&m_dwNumDevs, &m_dwAPIVersion, &LineExtParams))
{
return FALSE;
}
//m_dwTSPILineDeviceID = GetTSPLineDeviceID(CELLTSP_LINENAME_STRING);
m_dwTSPILineDeviceID = GetTSPLineDeviceID(CELLTSP_LINENAME_STRING);
// m_dwTSPILineDeviceID = GetTSPLineDeviceID(L"GPRS Modem - Data Port as COM7:");
if ( m_dwTSPILineDeviceID == (DWORD)-1 )
{
::lineShutdown(m_hLineApp);
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);
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);
return FALSE;
}
LINEGENERALINFO lviGeneralInfo;
lviGeneralInfo.dwTotalSize = sizeof(lviGeneralInfo);
LONG lRes = ::lineGetGeneralInfo(m_hLine, &lviGeneralInfo);
if (lRes != 0 && lRes != LINEERR_STRUCTURETOOSMALL)
{
//TCHAR szMsg[255];
//GetTAPIErrorMsg(szMsg,sizeof(szMsg), lRes);
::lineClose(m_hLine);
::lineShutdown(m_hLineApp);
return FALSE;
}
////////////////////////////////
LPLINEGENERALINFO plviGeneralInfo;
//LPTSTR tsManufacturer, tsModel, tsRevision, tsSerialNumber,
// tsSubscriberNumber;
//CString sInfo;
LPBYTE pLineGeneralInfoBytes = NULL;
pLineGeneralInfoBytes = new BYTE[lviGeneralInfo.dwNeededSize];
plviGeneralInfo = (LPLINEGENERALINFO)pLineGeneralInfoBytes;
if(pLineGeneralInfoBytes != NULL)
{
plviGeneralInfo->dwTotalSize = lviGeneralInfo.dwNeededSize;
if ( (lRes = ::lineGetGeneralInfo(m_hLine, plviGeneralInfo)) != 0 )
{
::lineClose(m_hLine);
::lineShutdown(m_hLineApp);
return FALSE;
}
else
{
TCHAR szUnavailable[] = L"Unavailable";
if(plviGeneralInfo->dwManufacturerSize)
{
tsManufacturer = (WCHAR*)(((BYTE*)plviGeneralInfo)
+plviGeneralInfo->dwManufacturerOffset);
}
else
{
tsManufacturer = szUnavailable;
}
//--制造商
mygenralinfo.Manufacturer = tsManufacturer;
if(plviGeneralInfo->dwModelSize)
{
tsModel = (WCHAR*)(((BYTE*)plviGeneralInfo)
+plviGeneralInfo->dwModelOffset);
}
else
{
tsModel = szUnavailable;
}
//--型号
mygenralinfo.Model = tsModel;
if(plviGeneralInfo->dwRevisionSize)
{
tsRevision = (WCHAR*)(((BYTE*)plviGeneralInfo)
+plviGeneralInfo->dwRevisionOffset);
}
else
{
tsRevision = szUnavailable;
}
//-- 软件版本
mygenralinfo.Revision = tsRevision;
if(plviGeneralInfo->dwSerialNumberSize)
{
tsSerialNumber = (WCHAR*)(((BYTE*)plviGeneralInfo)
+plviGeneralInfo->dwSerialNumberOffset);
}
else
{
tsSerialNumber = szUnavailable;
}
//--IMEI号,设备唯一标识
mygenralinfo.SerialNumber = tsSerialNumber;
if(plviGeneralInfo->dwSubscriberNumberSize)
{
tsSubscriberNumber = (WCHAR*)(((BYTE*)plviGeneralInfo)
+plviGeneralInfo->dwSubscriberNumberOffset);
}
else
{
tsSubscriberNumber = szUnavailable;
}
//-- IMSI号,SIM卡序列号
mygenralinfo.SubscriberNumber = tsSubscriberNumber;
//MessageBox(tsSubscriberNumber);
}
}
delete [] pLineGeneralInfoBytes;
return TRUE;
}
void CIMSIDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
BOOL Info = GetHWInfo(mygenralinfo);
CString SerialNumber = (CString)tsSerialNumber;
AfxMessageBox(SerialNumber);
//GetDlgItem(IDC_EDIT1)->ShowWindow((int)tsSerialNumber);
CString SubscriberNumber = (CString)tsSubscriberNumber;
AfxMessageBox(SubscriberNumber);
//GetDlgItem(IDC_EDIT2)->ShowWindow(SubscriberNumber);
//DWORD DeviceID = MobileHwInfo::GetTSPLineDeviceID();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -