Connection Manager and VB.NET

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.
 
P

Peter Foot [MVP]

In VB.NET Long is a 64bit integer. Change you "Long"s to "Integer"s (32bit)

Peter
 
G

Guest

Thanks for your reply, Peter

I changed Long to Integer, but with no success. I have other parts of the
code using ConnMgr with success, namely EnumDestinations, which works fine
enumerating all destinations available (although I had to do some special
marshalling of the fixed char array...). I just can´t get the
"EstablishConnection" and "EstablishConnectionSync" calls to work. It's a bit
frustrating at this point... Any other suggestions would be valuable.

Thanks,
Rogerio
 
G

Guest

OK, I figured it out: must marshal the ConnectionInfo structure element by
element, since it is complex (includes a GUID structure in it; followed the
C# outline in OpenNETCF); must define the function SHARED; must define the
hConn argument as "ByRef Integer".

After doing this it works fine!

Thanks for the helpful replies.

Rogerio
 
N

Nimzo vich via DotNetMonster.com

Can you please post your code..i would really appreciate it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top