I have problem accessing phonebook in VB.NET2005. I am using a MotorolaMPx220. My code is below.
I am getting error message "The remote connection to the device has been lost. Please verify the device connection and restart debugging"
I am not sure about the error.Can anyone help me to find out the error??
VB.NET:
<DllImport([COLOR=#800000]"Cellcore.dll"[/COLOR], SetLastError:=[COLOR=#0000ff]True[/COLOR], CharSet:=CharSet.Unicode)> _
[COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Shared[/COLOR] [COLOR=#0000ff]Function[/COLOR] SimReadPhonebookEntry([COLOR=#0000ff]ByVal[/COLOR] hSim [COLOR=#0000ff]As[/COLOR] IntPtr, [COLOR=#0000ff]ByVal[/COLOR] dwLocation [COLOR=#0000ff]As[/COLOR] Int32, [COLOR=#0000ff]ByVal[/COLOR] dwIndex [COLOR=#0000ff]As[/COLOR] Int32, [COLOR=#0000ff]ByRef[/COLOR] lpPhonebookEntry [COLOR=#0000ff]As[/COLOR] SimPhoneBookEntry) [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Boolean
[/COLOR][COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Function
[/COLOR]
<StructLayout(LayoutKind.Sequential)> _
[COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Structure[/COLOR] SimPhoneBookEntry
[COLOR=#0000ff]Public[/COLOR] cbSize [COLOR=#0000ff]As[/COLOR] IntPtr
[COLOR=#0000ff]Public[/COLOR] dwParams [COLOR=#0000ff]As[/COLOR] IntPtr
[COLOR=#0000ff]Public[/COLOR] lpszAddress [COLOR=#0000ff]As[/COLOR] IntPtr
[COLOR=#0000ff]Public[/COLOR] dwAddressType [COLOR=#0000ff]As[/COLOR] IntPtr
[COLOR=#0000ff]Public[/COLOR] dwNumPlan [COLOR=#0000ff]As[/COLOR] IntPtr
[COLOR=#0000ff]Public[/COLOR] lpszText [COLOR=#0000ff]As[/COLOR] IntPtr
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Structure[/COLOR] [COLOR=#008000]'SimPhoneBookEntry
[/COLOR]
[COLOR=blue]Public Sub[/COLOR] ReadPhoneBook()
[COLOR=#0000ff]Dim[/COLOR] hSim [COLOR=#0000ff]As[/COLOR] IntPtr
[COLOR=#0000ff]Dim[/COLOR] usedLoc [COLOR=#0000ff]As[/COLOR] UInt32
[COLOR=#0000ff]Dim[/COLOR] totalLoc [COLOR=#0000ff]As[/COLOR] UInt32
[COLOR=#0000ff]Dim[/COLOR] lpPhoneBookEntry [COLOR=#0000ff]As[/COLOR] Sim_Manager.SimPhoneBookEntry [COLOR=#008000]'= New [/COLOR][COLOR=#008000]
[/COLOR][COLOR=#0000ff]Try[/COLOR]
[COLOR=#0000ff]
[/COLOR][COLOR=#0000ff]Dim[/COLOR] val [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = Sim_Manager.SimInitialize(0, 0, 0, hSim)
Sim_Manager.SimGetPhonebookStatus(hSim, 16, usedLoc, totalLoc)
Sim_Manager.SimReadPhonebookEntry(hSim, 16, 1 ,pPhoneBookEntry)
Sim_Manager.SimDeinitialize(hSim)
[COLOR=#0000ff]Catch[/COLOR] ex [COLOR=#0000ff]As[/COLOR] Exception
MessageBox.Show(System.Runtime.InteropServices.Marshal.GetLastWin32Error())
MessageBox.Show(ex.ToString)
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Try[/COLOR]
[COLOR=blue]End Sub[/COLOR]
I am not sure about the error.Can anyone help me to find out the error??
Last edited: