This VB.NET code will work on Smartphone and Pocket PC Phone devices and return details of the current GSM operator (though it probably works on CDMA also). It relies on Alex Feinman's excellent TAPI wrapper whish you can download here. Using the library we create a line object which we pass the handle of (line.hline) into lineGetCurrentOperator, one of the ExTAPI functions. For simplicity the structure is just passed as one big byte array then the strings are copied out from it and have trailing nulls chopped off.
'gets the textual representation of the operatorPublic Function GetCurrentOperator(ByVal line As OpenNETCF.TAPI.Line) As OperatorDim result As IntegerDim nullindex As Integer'stores operator detailsDim lo As New OperatorDim buff(140) As Byte'copy LINEOPERATOR_USEFIRSTAVAILABLEINDEX to structBitConverter.GetBytes(-1).CopyTo(buff, 0)'call tapi methodresult = lineGetCurrentOperator(line.hLine, buff)If result < 0 Then'error encounteredThrow New System.Runtime.InteropServices.ExternalException("TAPI Error getting operator: " + result.ToString())End If'indexlo.Index = BitConverter.ToInt32(buff, 0)'get statuslo.Status = BitConverter.ToInt32(buff, 4)'get valid fieldslo.ValidFields = CType(BitConverter.ToInt32(buff, 8), OperatorFormat)'long nameIf (lo.ValidFields And OperatorFormat.AlphaLong) = OperatorFormat.AlphaLong Thenlo.LongName = System.Text.Encoding.Unicode.GetString(buff, 12, 64)nullindex = lo.LongName.IndexOf(Chr(0))If nullindex > -1 Thenlo.LongName = lo.LongName.Substring(0, nullindex)End IfEnd If'copy short nameIf (lo.ValidFields And OperatorFormat.AlphaShort) = OperatorFormat.AlphaShort Thenlo.ShortName = System.Text.Encoding.Unicode.GetString(buff, 76, 32)nullindex = lo.ShortName.IndexOf(Chr(0))If nullindex > -1 Thenlo.ShortName = lo.ShortName.Substring(0, nullindex)End IfEnd If'copy num nameIf (lo.ValidFields And OperatorFormat.Numeric) = OperatorFormat.Numeric Thenlo.NumName = System.Text.Encoding.Unicode.GetString(buff, 108, 32)nullindex = lo.NumName.IndexOf(Chr(0))If nullindex > -1 Thenlo.NumName = lo.NumName.Substring(0, nullindex)End IfEnd IfReturn loEnd FunctionDeclare Function lineGetCurrentOperator Lib "cellcore.dll" (ByVal hLine As IntPtr, ByVal operator As Byte()) As IntegerPublic Class Operator Public Index As Integer Public ValidFields As OperatorFormat Public Status As Integer Public LongName As String Public ShortName As String Public NumName As StringEnd Class_Public Enum OperatorFormat None = &H0 AlphaShort = &H1 AlphaLong = &H2 Numeric = &H4End Enum
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.