WINDOWS MOBILE获取运营商名称
在WM下获得运营商的名称需要用TAPI,找了个例子给大家SHARE一下
//在CRegInfoDlg类中定义成员变量
HLINEAPP m_hLineApp;
HLINE m_hLine;
TCHAR m_tchOpertionNum[MAX_PATH];
//函数实现
BOOL CRegInfoDlg::GetCurrentOperator(TCHAR* szCurrentOperator,TCHAR* szCurrentOperatorNumName)
{
LINEOPERATOR CurrentOperator;
if ( lineGetCurrentOperator( m_hLine, &CurrentOperator ) )
{
return FALSE;
}
_tcscpy( szCurrentOperator, CurrentOperator.lpszLongName );
_tcscpy( szCurrentOperatorNumName, CurrentOperator.lpszNumName );
return TRUE;
}
void CALLBACK TAPIProc( DWORD hDevice, DWORD dwMessage, DWORD dwInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3 )
{
}
BOOL CRegInfoDlg::InitExTAPI()
{
DWORD dwNumDevs;
DWORD dwAPIVersion = TAPI_API_HIGH_VERSION;
LINEINITIALIZEEXPARAMS liep;
DWORD dwExtVersion;
// set the line init params
liep.dwTotalSize = sizeof(liep);
liep.dwOptions = LINEINITIALIZEEXOPTION_USEHIDDENWINDOW;
if (lineInitializeEx( &m_hLineApp, _Module.GetModuleInstance( ), &TAPIProc, TEXT("EXTAPISAMPLE"),
&dwNumDevs, &dwAPIVersion, &liep)) {
return FALSE;
}//这个比较主要INIT
// get the device ID
DWORD dwTAPILineDeviceID = GetTSPLineDeviceID(m_hLineApp, dwNumDevs,
TAPI_API_LOW_VERSION,
TAPI_API_HIGH_VERSION,
(L"Cellular Line"));
// error getting the line device ID?
if (0xffffffff == dwTAPILineDeviceID) {
lineShutdown(m_hLineApp);
return FALSE;
}
// now try and open the line
const DWORD dwMediaMode = LINEMEDIAMODE_DATAMODEM | LINEMEDIAMODE_INTERACTIVEVOICE;
if(lineOpen(m_hLineApp, dwTAPILineDeviceID,
&m_hLine, dwAPIVersion, 0, 0,
LINECALLPRIVILEGE_OWNER, dwMediaMode, 0)) {
lineShutdown(m_hLineApp);
return FALSE;
}
// set up ExTAPI
if (lineNegotiateExtVersion(m_hLineApp, dwTAPILineDeviceID,
dwAPIVersion, EXT_API_LOW_VERSION,
EXT_API_HIGH_VERSION, &dwExtVersion)) {
lineClose(m_hLine);
lineShutdown(m_hLineApp);
return FALSE;
}
TCHAR tNowOpertion[MAX_PATH]={0};
SecureZeroMemory( m_tchOpertionNum, ( MAX_PATH * sizeof( TCHAR ) ) );
GetCurrentOperator( tNowOpertion, m_tchOpertionNum );//这句最终得到结果
return TRUE;
}
DWORD CRegInfoDlg::GetTSPLineDeviceID( const HLINEAPP hLineApp,
const DWORD dwNumberDevices, const DWORD dwAPIVersionLow,
const DWORD dwAPIVersionHigh, const TCHAR* const psTSPLineName )
{
DWORD dwReturn = 0xffffffff;
for( DWORD dwCurrentDevID = 0 ; dwCurrentDevID < dwNumberDevices ; dwCurrentDevID++ )
{
DWORD dwAPIVersion;
LINEEXTENSIONID LineExtensionID;
if(0 == lineNegotiateAPIVersion(hLineApp, dwCurrentDevID,
dwAPIVersionLow, dwAPIVersionHigh,
&dwAPIVersion, &LineExtensionID)) {
LINEDEVCAPS LineDevCaps;
LineDevCaps.dwTotalSize = sizeof(LineDevCaps);
if(0 == lineGetDevCaps(hLineApp, dwCurrentDevID,
dwAPIVersion, 0, &LineDevCaps)) {
BYTE* pLineDevCapsBytes = new BYTE[LineDevCaps.dwNeededSize];
if(0 != pLineDevCapsBytes) {
LINEDEVCAPS* pLineDevCaps = (LINEDEVCAPS*)pLineDevCapsBytes;
pLineDevCaps->dwTotalSize = LineDevCaps.dwNeededSize;
if(0 == lineGetDevCaps(hLineApp, dwCurrentDevID,
dwAPIVersion, 0, pLineDevCaps)) {
if(0 == _tcscmp((TCHAR*)((BYTE*)pLineDevCaps+pLineDevCaps->dwLineNameOffset), psTSPLineName)) {
dwReturn = dwCurrentDevID;
}
}
delete[] pLineDevCapsBytes;
}
}
}
}
return dwReturn;
}