G
Guest
Hi
I´m having some trouble using ConnMgr in VB.NET to establish an Internet
connection on my Pocket PC. Any help or suggestion would be greatly
appreciated!
The code in my class goes like this:
<code>
<StructLayout(LayoutKind.Sequential)> Public Structure
CONNMGR_CONNECTIONINFO
Dim cbSize As Integer
Dim dwParams As Integer ' Valid parms, set of
CONNMGR_PARAM_*
Dim dwFlags As Integer ' Connection flags, set of
CONNMGR_FLAG_*
Dim dwPriority As Integer ' Priority, one of
CONNMGR_PRIORITY_*
Dim bExclusive As Boolean ' Connection is exclusive, see
comments
Dim bDisabled As Boolean ' Don't actually connect
Dim guidDestNet As Guid ' GUID of network to connect to
Dim hWnd As Long ' hWnd to post status change
messages to
Dim uMsg As Long ' Msg to use when posting status
changes
Dim lParam As Long ' lParam to use when posting status
changes
Dim ulMaxCost As Long ' Max acceptable cost of connection
Dim ulMinRcvBw As Long ' Min acceptable receive bandwidth
of connection
Dim ulMaxConnLatency As Long ' Max acceptable connect latency
End Structure
<DllImport("cellcore.dll", SetLastError:=True)> _
Private Function ConnMgrEstablishConnectionSync( _
ByVal pConnInfo As IntPtr, _
ByRef phConnection As Long, _
ByVal dwDelay As Integer, _
ByRef dwStatus As Integer) As IntPtr ' Final status value, one of
CONNMGR_STATUS_*
End Function
Public Sub CConnect()
Dim structConn1 As CONNMGR_CONNECTIONINFO = New
CONNMGR_CONNECTIONINFO, iDelay as Integer, iStatus as Integer, hConn as Long
Dim res as IntPtr
structConn1.dwParams = Me.CONNMGR_PARAM_GUIDDESTNET
structConn1.dwPriority = Me.CONNMGR_PRIORITY_HIPRIBKGND
structConn1.dwFlags = 0
structConn1.bDisabled = False
structConn1.bExclusive = False
structConn1.hWnd = 0
structConn1.lParam = 0
structConn1.uMsg = 0
structConn1.guidDestNet = IID_DestNetInternet 'Defined elsewhere
structConn1.cbSize = Marshal.SizeOf(structConn1) + (64 *
Marshal.SystemDefaultCharSize)
Dim Ptr As IntPtr = Memory.AllocHLocal(Marshal.SizeOf(structConn1) +
(64 * Marshal.SystemDefaultCharSize))
Marshal.StructureToPtr(structConn1, Ptr, False)
iDelay = 20000
res = Me.ConnMgrEstablishConnectionSync(Ptr, hConn, iDelay, iStatus)
'Check for success in RES
....
End Sub
</code>
The problem is that the HRESULT (RES) claims success in calling the
function, but the iStatus is CONNMGR_STATUS_CONNECTIONFAILED; tried a lot of
different stuff but still the same Status (even after deploying to the device
and running out of the craddle). It should be able to start the GPRS
connection configured in ConnMgr...
Any suggestion on what is missing? Thanks.
I´m having some trouble using ConnMgr in VB.NET to establish an Internet
connection on my Pocket PC. Any help or suggestion would be greatly
appreciated!
The code in my class goes like this:
<code>
<StructLayout(LayoutKind.Sequential)> Public Structure
CONNMGR_CONNECTIONINFO
Dim cbSize As Integer
Dim dwParams As Integer ' Valid parms, set of
CONNMGR_PARAM_*
Dim dwFlags As Integer ' Connection flags, set of
CONNMGR_FLAG_*
Dim dwPriority As Integer ' Priority, one of
CONNMGR_PRIORITY_*
Dim bExclusive As Boolean ' Connection is exclusive, see
comments
Dim bDisabled As Boolean ' Don't actually connect
Dim guidDestNet As Guid ' GUID of network to connect to
Dim hWnd As Long ' hWnd to post status change
messages to
Dim uMsg As Long ' Msg to use when posting status
changes
Dim lParam As Long ' lParam to use when posting status
changes
Dim ulMaxCost As Long ' Max acceptable cost of connection
Dim ulMinRcvBw As Long ' Min acceptable receive bandwidth
of connection
Dim ulMaxConnLatency As Long ' Max acceptable connect latency
End Structure
<DllImport("cellcore.dll", SetLastError:=True)> _
Private Function ConnMgrEstablishConnectionSync( _
ByVal pConnInfo As IntPtr, _
ByRef phConnection As Long, _
ByVal dwDelay As Integer, _
ByRef dwStatus As Integer) As IntPtr ' Final status value, one of
CONNMGR_STATUS_*
End Function
Public Sub CConnect()
Dim structConn1 As CONNMGR_CONNECTIONINFO = New
CONNMGR_CONNECTIONINFO, iDelay as Integer, iStatus as Integer, hConn as Long
Dim res as IntPtr
structConn1.dwParams = Me.CONNMGR_PARAM_GUIDDESTNET
structConn1.dwPriority = Me.CONNMGR_PRIORITY_HIPRIBKGND
structConn1.dwFlags = 0
structConn1.bDisabled = False
structConn1.bExclusive = False
structConn1.hWnd = 0
structConn1.lParam = 0
structConn1.uMsg = 0
structConn1.guidDestNet = IID_DestNetInternet 'Defined elsewhere
structConn1.cbSize = Marshal.SizeOf(structConn1) + (64 *
Marshal.SystemDefaultCharSize)
Dim Ptr As IntPtr = Memory.AllocHLocal(Marshal.SizeOf(structConn1) +
(64 * Marshal.SystemDefaultCharSize))
Marshal.StructureToPtr(structConn1, Ptr, False)
iDelay = 20000
res = Me.ConnMgrEstablishConnectionSync(Ptr, hConn, iDelay, iStatus)
'Check for success in RES
....
End Sub
</code>
The problem is that the HRESULT (RES) claims success in calling the
function, but the iStatus is CONNMGR_STATUS_CONNECTIONFAILED; tried a lot of
different stuff but still the same Status (even after deploying to the device
and running out of the craddle). It should be able to start the GPRS
connection configured in ConnMgr...
Any suggestion on what is missing? Thanks.