如何抓取SIM卡中的連絡人資訊
在論壇中Microsoft.WindowsMobile.Status.SystemState.OwnerPhoneNumber有提問到要如何抓取SIM卡中的連絡人,這個部分必須要用到API去存取,下面是相關的程式碼,可以參考看看
模組的程式碼
呼叫的範例
模組的程式碼
Module Module1
Public Const S_OK As Int64 = &H0
Public Const SIM_CAPSTYPE_ALL As Integer = &H3F
Public Const SIM_PBSTORAGE_SIM As Integer = &H10
Public Const SIM_SMSSTORAGE_SIM As Integer = &H2
_
Public Structure SIMPHONEBOOKENTRY
Public cbSize As UInteger
Public dwParams As UInteger
_
Public lpszAddress As String
Public dwAddressType As UInteger
Public dwNumPlan As UInteger
_
Public lpszText As String
End Structure
_
Public Function SimInitialize(ByVal dwFlags As UInt32, ByVal lpfnCallBack As Integer, _
ByVal dwParam As UInt32, ByRef lphSim As Integer) As Integer
End Function
_
Public Function SimGetPhonebookStatus(ByVal hSim As Integer, ByVal dwLocation As UInt32, _
ByRef lpdwUsed As UInt32, ByRef lpdwTotal As UInt32) As Integer
End Function
_
Public Function SimReadPhonebookEntry(ByVal hSim As Integer, ByVal dwLocation As UInt32, _
ByVal dwIndex As UInt32, ByRef entry As SIMPHONEBOOKENTRY) As Integer
End Function
End Module
呼叫的範例
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hSim As Integer = 0
Dim result As Integer = SimInitialize(0, 0, 0, hSim)
If (result <> 0) Then Throw New Exception("Failed to Open Call Log")
Dim uiUsed As UInt32 = 0
Dim uiTotal As UInt32 = 0
result = SimGetPhonebookStatus(hSim, SIM_PBSTORAGE_SIM, uiUsed, uiTotal)
Dim entry As SIMPHONEBOOKENTRY = New SIMPHONEBOOKENTRY
entry.cbSize = Marshal.SizeOf(entry.GetType)
For i As Integer = 1 To uiUsed
result = SimReadPhonebookEntry(hSim, SIM_PBSTORAGE_SIM, i, entry)
If result = 0 Then
ListBox1.Items.Add(entry.lpszText & "," & entry.lpszAddress)
End If
Next
End Sub
留言