PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Help with Connection Manager PInvoking

Reply

Help with Connection Manager PInvoking

 
Thread Tools Rate Thread
Old 08-07-2003, 11:03 PM   #1
Justin Marshall
Guest
 
Posts: n/a
Default Help with Connection Manager PInvoking


Greetings,

I am having difficulty calling the ConnMgrEstablishConnection function
through PInvoke which I hope somebody can assist with.
I have used the CMHelper project in the PPC2002SDK as a basis for this code.

The call to ConnMgrMapURL works fine, but when I try and call
ConnMgrEstablishConnection (via the EstablishConnection function below), I
get a NotSupportedException.
I suspect that it may be a problem with the ConnMgr_ConnectionInfo structure
(eg. data types). I had tried hWnd and lParam with Integer data type as well
with the same effect.

My call to ConnMgrConnectionStatus also achieves the same result but
possibly because I do not have a valid handle.

Thanks for any help anybody is able to provide.

Regards,
Justin Marshall.



Following is the code I currently have (in VB.Net):

'---------------------------------------------------------------------
Imports System.Runtime.InteropServices

Public Class CConnMgr

Private m_lngConnectionHandle As Long

Private Const CONNMGR_PARAM_GUIDDESTNET = 1 ' @constdefine guidDestNet
field is valid

Private Const CONNMGR_PARAM_MAXCONNLATENCY = 8 ' @constdefine
MaxConnLatency field is valid

Private Const CONNMGR_PRIORITY_USERINTERACTIVE = &H8000

Public Const CONNMGR_STATUS_UNKNOWN = &H0 ' @constdefine Unknown status
Public Const CONNMGR_STATUS_CONNECTED = &H10 ' @constdefine Connection
is up
Public Const CONNMGR_STATUS_DISCONNECTED = &H20 ' @constdefine
Connection is disconnected
Public Const CONNMGR_STATUS_CONNECTIONFAILED = &H21 ' @constdefine
Connection failed and cannot not be reestablished
Public Const CONNMGR_STATUS_CONNECTIONCANCELED = &H22 ' @constdefine
User aborted connection
Public Const CONNMGR_STATUS_CONNECTIONDISABLED = &H23 ' @constdefine
Connection is ready to connect but disabled
Public Const CONNMGR_STATUS_NOPATHTODESTINATION = &H24 ' @constdefine No
path could be found to destination
Public Const CONNMGR_STATUS_WAITINGFORPATH = &H25 ' @constdefine Waiting
for a path to the destination
Public Const CONNMGR_STATUS_WAITINGFORPHONE = &H26 ' @constdefine Voice
call is in progress
Public Const CONNMGR_STATUS_WAITINGCONNECTION = &H40 ' @constdefine
Attempting to connect
Public Const CONNMGR_STATUS_WAITINGFORRESOURCE = &H41 ' @constdefine
Resource is in use by another connection
Public Const CONNMGR_STATUS_WAITINGFORNETWORK = &H42 ' @constdefine No
path could be found to destination
Public Const CONNMGR_STATUS_WAITINGDISCONNECTION = &H80 ' @constdefine
Connection is being brought down
Public Const CONNMGR_STATUS_WAITINGCONNECTIONABORT = &H81 ' @constdefine
Aborting connection attempt

Public Structure ConnMgr_ConnectionInfo
Public Size As Long
Public Params As Long
Public Flags As Long
Public Priority As Long

Public Exclusive As Boolean
Public Disabled As Boolean

Public DestNetGuid As Guid

Public hWnd As IntPtr
Public Msg As Integer
Public lParam As IntPtr

Public MaxCost As Long
Public MinRcvBw As Long
Public MaxConnLatency As Long
End Structure

<DllImport("cellcore.dll")> Private Shared Function
ConnMgrEnumDestinations(ByVal DestIndex As Integer, ByRef DestInfo As
ConnMgr_DestinationInfo) As Integer
End Function
<DllImport("cellcore.dll")> Private Shared Function
ConnMgrEstablishConnection(ByRef ConnInfo As ConnMgr_ConnectionInfo, ByRef
ConnHandle As Long) As Integer
End Function
<DllImport("cellcore.dll")> Private Shared Function
ConnMgrEstablishConnectionSync(ByRef ConnInfo As ConnMgr_ConnectionInfo,
ByRef ConnHandle As Long, ByVal Timeout As Long, ByRef FinalStatus As Long)
As Integer
End Function
<DllImport("cellcore.dll")> Private Shared Function
ConnMgrConnectionStatus(ByVal hConn As Long, ByRef iStatus As Long) As
Integer
End Function
<DllImport("cellcore.dll")> Private Shared Function ConnMgrMapURL(ByVal
URL As String, ByRef NetworkGuid As Guid, ByRef GuidIndex As Long) As
Integer
End Function
<DllImport("cellcore.dll")> Private Shared Function
ConnMgrReleaseConnection(ByVal ConnHandle As Long, ByVal
AllowConnectionToBeCached As Boolean) As Integer
End Function

Public Function GetNetworkFromPath(ByVal URL As String) As Guid

Dim NetworkGuid As Guid
Dim GuidIndex As Long
Dim Result As Integer

Result = ConnMgrMapURL(URL, NetworkGuid, GuidIndex)

Return NetworkGuid

End Function

Public Function EstablishConnection() As Integer

Dim ConnInfo As ConnMgr_ConnectionInfo
Dim ConnHandle As Long
Dim FinalStatus As Long
Dim Result As Integer

ConnInfo.Size = Marshal.SizeOf(ConnInfo)
ConnInfo.Params = CONNMGR_PARAM_GUIDDESTNET Or
CONNMGR_PARAM_MAXCONNLATENCY
ConnInfo.Flags = 0
ConnInfo.MaxConnLatency = 4000
ConnInfo.Disabled = False
ConnInfo.Priority = CONNMGR_PRIORITY_USERINTERACTIVE
ConnInfo.DestNetGuid = GetNetworkFromPath("http://server")

Try
Result = ConnMgrEstablishConnectionSync(ConnInfo, ConnHandle,
4000, FinalStatus)
m_lngConnectionHandle = ConnHandle

MsgBox("Connection handle = " & ConnHandle.ToString)

Catch ex As System.NotSupportedException
MsgBox("NotSupportedError in EstablishConnection")

Catch ex As Exception
MsgBox("Error in EstablishConnection (" & ex.Message & ")")

End Try

End Function

Public Function Status() As Integer

Dim lngCurrentStatus As Long
Dim intResult As Integer

intResult = ConnMgrConnectionStatus(m_lngConnectionHandle,
lngCurrentStatus)

Return lngCurrentStatus

End Function

End Class


  Reply With Quote
Old 08-07-2003, 11:16 PM   #2
Alex Feinman [MVP]
Guest
 
Posts: n/a
Default Re: Help with Connection Manager PInvoking

Replace all instances of Long with Integer. Long is not supported by
marshaller and unlike VB6 it is 64bit integer. YOu need 32-bit, which is
type Integer

"Justin Marshall" <hqtrainer@hotmail.com> wrote in message
news:eO0a5UaRDHA.2188@TK2MSFTNGP10.phx.gbl...
> Greetings,
>
> I am having difficulty calling the ConnMgrEstablishConnection function
> through PInvoke which I hope somebody can assist with.
> I have used the CMHelper project in the PPC2002SDK as a basis for this

code.
>
> The call to ConnMgrMapURL works fine, but when I try and call
> ConnMgrEstablishConnection (via the EstablishConnection function below), I
> get a NotSupportedException.
> I suspect that it may be a problem with the ConnMgr_ConnectionInfo

structure
> (eg. data types). I had tried hWnd and lParam with Integer data type as

well
> with the same effect.
>
> My call to ConnMgrConnectionStatus also achieves the same result but
> possibly because I do not have a valid handle.
>
> Thanks for any help anybody is able to provide.
>
> Regards,
> Justin Marshall.
>
>
>
> Following is the code I currently have (in VB.Net):
>
> '---------------------------------------------------------------------
> Imports System.Runtime.InteropServices
>
> Public Class CConnMgr
>
> Private m_lngConnectionHandle As Long
>
> Private Const CONNMGR_PARAM_GUIDDESTNET = 1 ' @constdefine guidDestNet
> field is valid
>
> Private Const CONNMGR_PARAM_MAXCONNLATENCY = 8 ' @constdefine
> MaxConnLatency field is valid
>
> Private Const CONNMGR_PRIORITY_USERINTERACTIVE = &H8000
>
> Public Const CONNMGR_STATUS_UNKNOWN = &H0 ' @constdefine Unknown

status
> Public Const CONNMGR_STATUS_CONNECTED = &H10 ' @constdefine Connection
> is up
> Public Const CONNMGR_STATUS_DISCONNECTED = &H20 ' @constdefine
> Connection is disconnected
> Public Const CONNMGR_STATUS_CONNECTIONFAILED = &H21 ' @constdefine
> Connection failed and cannot not be reestablished
> Public Const CONNMGR_STATUS_CONNECTIONCANCELED = &H22 ' @constdefine
> User aborted connection
> Public Const CONNMGR_STATUS_CONNECTIONDISABLED = &H23 ' @constdefine
> Connection is ready to connect but disabled
> Public Const CONNMGR_STATUS_NOPATHTODESTINATION = &H24 ' @constdefine

No
> path could be found to destination
> Public Const CONNMGR_STATUS_WAITINGFORPATH = &H25 ' @constdefine

Waiting
> for a path to the destination
> Public Const CONNMGR_STATUS_WAITINGFORPHONE = &H26 ' @constdefine

Voice
> call is in progress
> Public Const CONNMGR_STATUS_WAITINGCONNECTION = &H40 ' @constdefine
> Attempting to connect
> Public Const CONNMGR_STATUS_WAITINGFORRESOURCE = &H41 ' @constdefine
> Resource is in use by another connection
> Public Const CONNMGR_STATUS_WAITINGFORNETWORK = &H42 ' @constdefine No
> path could be found to destination
> Public Const CONNMGR_STATUS_WAITINGDISCONNECTION = &H80 ' @constdefine
> Connection is being brought down
> Public Const CONNMGR_STATUS_WAITINGCONNECTIONABORT = &H81 '

@constdefine
> Aborting connection attempt
>
> Public Structure ConnMgr_ConnectionInfo
> Public Size As Long
> Public Params As Long
> Public Flags As Long
> Public Priority As Long
>
> Public Exclusive As Boolean
> Public Disabled As Boolean
>
> Public DestNetGuid As Guid
>
> Public hWnd As IntPtr
> Public Msg As Integer
> Public lParam As IntPtr
>
> Public MaxCost As Long
> Public MinRcvBw As Long
> Public MaxConnLatency As Long
> End Structure
>
> <DllImport("cellcore.dll")> Private Shared Function
> ConnMgrEnumDestinations(ByVal DestIndex As Integer, ByRef DestInfo As
> ConnMgr_DestinationInfo) As Integer
> End Function
> <DllImport("cellcore.dll")> Private Shared Function
> ConnMgrEstablishConnection(ByRef ConnInfo As ConnMgr_ConnectionInfo, ByRef
> ConnHandle As Long) As Integer
> End Function
> <DllImport("cellcore.dll")> Private Shared Function
> ConnMgrEstablishConnectionSync(ByRef ConnInfo As ConnMgr_ConnectionInfo,
> ByRef ConnHandle As Long, ByVal Timeout As Long, ByRef FinalStatus As

Long)
> As Integer
> End Function
> <DllImport("cellcore.dll")> Private Shared Function
> ConnMgrConnectionStatus(ByVal hConn As Long, ByRef iStatus As Long) As
> Integer
> End Function
> <DllImport("cellcore.dll")> Private Shared Function

ConnMgrMapURL(ByVal
> URL As String, ByRef NetworkGuid As Guid, ByRef GuidIndex As Long) As
> Integer
> End Function
> <DllImport("cellcore.dll")> Private Shared Function
> ConnMgrReleaseConnection(ByVal ConnHandle As Long, ByVal
> AllowConnectionToBeCached As Boolean) As Integer
> End Function
>
> Public Function GetNetworkFromPath(ByVal URL As String) As Guid
>
> Dim NetworkGuid As Guid
> Dim GuidIndex As Long
> Dim Result As Integer
>
> Result = ConnMgrMapURL(URL, NetworkGuid, GuidIndex)
>
> Return NetworkGuid
>
> End Function
>
> Public Function EstablishConnection() As Integer
>
> Dim ConnInfo As ConnMgr_ConnectionInfo
> Dim ConnHandle As Long
> Dim FinalStatus As Long
> Dim Result As Integer
>
> ConnInfo.Size = Marshal.SizeOf(ConnInfo)
> ConnInfo.Params = CONNMGR_PARAM_GUIDDESTNET Or
> CONNMGR_PARAM_MAXCONNLATENCY
> ConnInfo.Flags = 0
> ConnInfo.MaxConnLatency = 4000
> ConnInfo.Disabled = False
> ConnInfo.Priority = CONNMGR_PRIORITY_USERINTERACTIVE
> ConnInfo.DestNetGuid = GetNetworkFromPath("http://server")
>
> Try
> Result = ConnMgrEstablishConnectionSync(ConnInfo, ConnHandle,
> 4000, FinalStatus)
> m_lngConnectionHandle = ConnHandle
>
> MsgBox("Connection handle = " & ConnHandle.ToString)
>
> Catch ex As System.NotSupportedException
> MsgBox("NotSupportedError in EstablishConnection")
>
> Catch ex As Exception
> MsgBox("Error in EstablishConnection (" & ex.Message & ")")
>
> End Try
>
> End Function
>
> Public Function Status() As Integer
>
> Dim lngCurrentStatus As Long
> Dim intResult As Integer
>
> intResult = ConnMgrConnectionStatus(m_lngConnectionHandle,
> lngCurrentStatus)
>
> Return lngCurrentStatus
>
> End Function
>
> End Class
>
>



  Reply With Quote
Old 09-07-2003, 12:41 AM   #3
Justin Marshall
Guest
 
Posts: n/a
Default Re: Help with Connection Manager PInvoking

Thanks for your prompt and exact help Alex. No more NotSupportedExceptions.
Brilliant.

Now, when I ask for a URL of "http://server" (as per posted code), I get a
status of CONNMGR_STATUS_NOPATHTODESTINATION. ConnMgrMapURL returns a valid
GUID for this address.
Yet when I enter this address into Pocket Internet Explorer, it correctly
dials out.
Same result if I try a URL of "http://www.microsoft.com".

Have you (or others) any experience or thoughts on this one?

Thanks again,
Justin.


"Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message
news:%233ul3baRDHA.2148@TK2MSFTNGP10.phx.gbl...
> Replace all instances of Long with Integer. Long is not supported by
> marshaller and unlike VB6 it is 64bit integer. YOu need 32-bit, which is
> type Integer
>
> "Justin Marshall" <hqtrainer@hotmail.com> wrote in message
> news:eO0a5UaRDHA.2188@TK2MSFTNGP10.phx.gbl...
> > Greetings,
> >
> > I am having difficulty calling the ConnMgrEstablishConnection function
> > through PInvoke which I hope somebody can assist with.
> > I have used the CMHelper project in the PPC2002SDK as a basis for this

> code.
> >
> > The call to ConnMgrMapURL works fine, but when I try and call
> > ConnMgrEstablishConnection (via the EstablishConnection function below),

I
> > get a NotSupportedException.
> > I suspect that it may be a problem with the ConnMgr_ConnectionInfo

> structure
> > (eg. data types). I had tried hWnd and lParam with Integer data type as

> well
> > with the same effect.
> >
> > My call to ConnMgrConnectionStatus also achieves the same result but
> > possibly because I do not have a valid handle.
> >
> > Thanks for any help anybody is able to provide.
> >
> > Regards,
> > Justin Marshall.
> >
> >
> >
> > Following is the code I currently have (in VB.Net):
> >
> > '---------------------------------------------------------------------
> > Imports System.Runtime.InteropServices
> >
> > Public Class CConnMgr
> >
> > Private m_lngConnectionHandle As Long
> >
> > Private Const CONNMGR_PARAM_GUIDDESTNET = 1 ' @constdefine

guidDestNet
> > field is valid
> >
> > Private Const CONNMGR_PARAM_MAXCONNLATENCY = 8 ' @constdefine
> > MaxConnLatency field is valid
> >
> > Private Const CONNMGR_PRIORITY_USERINTERACTIVE = &H8000
> >
> > Public Const CONNMGR_STATUS_UNKNOWN = &H0 ' @constdefine Unknown

> status
> > Public Const CONNMGR_STATUS_CONNECTED = &H10 ' @constdefine

Connection
> > is up
> > Public Const CONNMGR_STATUS_DISCONNECTED = &H20 ' @constdefine
> > Connection is disconnected
> > Public Const CONNMGR_STATUS_CONNECTIONFAILED = &H21 ' @constdefine
> > Connection failed and cannot not be reestablished
> > Public Const CONNMGR_STATUS_CONNECTIONCANCELED = &H22 ' @constdefine
> > User aborted connection
> > Public Const CONNMGR_STATUS_CONNECTIONDISABLED = &H23 ' @constdefine
> > Connection is ready to connect but disabled
> > Public Const CONNMGR_STATUS_NOPATHTODESTINATION = &H24 '

@constdefine
> No
> > path could be found to destination
> > Public Const CONNMGR_STATUS_WAITINGFORPATH = &H25 ' @constdefine

> Waiting
> > for a path to the destination
> > Public Const CONNMGR_STATUS_WAITINGFORPHONE = &H26 ' @constdefine

> Voice
> > call is in progress
> > Public Const CONNMGR_STATUS_WAITINGCONNECTION = &H40 ' @constdefine
> > Attempting to connect
> > Public Const CONNMGR_STATUS_WAITINGFORRESOURCE = &H41 ' @constdefine
> > Resource is in use by another connection
> > Public Const CONNMGR_STATUS_WAITINGFORNETWORK = &H42 ' @constdefine

No
> > path could be found to destination
> > Public Const CONNMGR_STATUS_WAITINGDISCONNECTION = &H80 '

@constdefine
> > Connection is being brought down
> > Public Const CONNMGR_STATUS_WAITINGCONNECTIONABORT = &H81 '

> @constdefine
> > Aborting connection attempt
> >
> > Public Structure ConnMgr_ConnectionInfo
> > Public Size As Long
> > Public Params As Long
> > Public Flags As Long
> > Public Priority As Long
> >
> > Public Exclusive As Boolean
> > Public Disabled As Boolean
> >
> > Public DestNetGuid As Guid
> >
> > Public hWnd As IntPtr
> > Public Msg As Integer
> > Public lParam As IntPtr
> >
> > Public MaxCost As Long
> > Public MinRcvBw As Long
> > Public MaxConnLatency As Long
> > End Structure
> >
> > <DllImport("cellcore.dll")> Private Shared Function
> > ConnMgrEnumDestinations(ByVal DestIndex As Integer, ByRef DestInfo As
> > ConnMgr_DestinationInfo) As Integer
> > End Function
> > <DllImport("cellcore.dll")> Private Shared Function
> > ConnMgrEstablishConnection(ByRef ConnInfo As ConnMgr_ConnectionInfo,

ByRef
> > ConnHandle As Long) As Integer
> > End Function
> > <DllImport("cellcore.dll")> Private Shared Function
> > ConnMgrEstablishConnectionSync(ByRef ConnInfo As ConnMgr_ConnectionInfo,
> > ByRef ConnHandle As Long, ByVal Timeout As Long, ByRef FinalStatus As

> Long)
> > As Integer
> > End Function
> > <DllImport("cellcore.dll")> Private Shared Function
> > ConnMgrConnectionStatus(ByVal hConn As Long, ByRef iStatus As Long) As
> > Integer
> > End Function
> > <DllImport("cellcore.dll")> Private Shared Function

> ConnMgrMapURL(ByVal
> > URL As String, ByRef NetworkGuid As Guid, ByRef GuidIndex As Long) As
> > Integer
> > End Function
> > <DllImport("cellcore.dll")> Private Shared Function
> > ConnMgrReleaseConnection(ByVal ConnHandle As Long, ByVal
> > AllowConnectionToBeCached As Boolean) As Integer
> > End Function
> >
> > Public Function GetNetworkFromPath(ByVal URL As String) As Guid
> >
> > Dim NetworkGuid As Guid
> > Dim GuidIndex As Long
> > Dim Result As Integer
> >
> > Result = ConnMgrMapURL(URL, NetworkGuid, GuidIndex)
> >
> > Return NetworkGuid
> >
> > End Function
> >
> > Public Function EstablishConnection() As Integer
> >
> > Dim ConnInfo As ConnMgr_ConnectionInfo
> > Dim ConnHandle As Long
> > Dim FinalStatus As Long
> > Dim Result As Integer
> >
> > ConnInfo.Size = Marshal.SizeOf(ConnInfo)
> > ConnInfo.Params = CONNMGR_PARAM_GUIDDESTNET Or
> > CONNMGR_PARAM_MAXCONNLATENCY
> > ConnInfo.Flags = 0
> > ConnInfo.MaxConnLatency = 4000
> > ConnInfo.Disabled = False
> > ConnInfo.Priority = CONNMGR_PRIORITY_USERINTERACTIVE
> > ConnInfo.DestNetGuid = GetNetworkFromPath("http://server")
> >
> > Try
> > Result = ConnMgrEstablishConnectionSync(ConnInfo,

ConnHandle,
> > 4000, FinalStatus)
> > m_lngConnectionHandle = ConnHandle
> >
> > MsgBox("Connection handle = " & ConnHandle.ToString)
> >
> > Catch ex As System.NotSupportedException
> > MsgBox("NotSupportedError in EstablishConnection")
> >
> > Catch ex As Exception
> > MsgBox("Error in EstablishConnection (" & ex.Message & ")")
> >
> > End Try
> >
> > End Function
> >
> > Public Function Status() As Integer
> >
> > Dim lngCurrentStatus As Long
> > Dim intResult As Integer
> >
> > intResult = ConnMgrConnectionStatus(m_lngConnectionHandle,
> > lngCurrentStatus)
> >
> > Return lngCurrentStatus
> >
> > End Function
> >
> > End Class
> >
> >

>
>



  Reply With Quote
Old 09-07-2003, 01:26 AM   #4
Alex Feinman [MVP]
Guest
 
Posts: n/a
Default Re: Help with Connection Manager PInvoking

Alex Yakhnin and I have actually created RAS.NET component that includes
Connection Manager wrapper.
Off the top of my head I don't see a problem with your code - what I use is
very similar although I prefer establishing connection asynchronously

"Justin Marshall" <hqtrainer@hotmail.com> wrote in message
news:OXPxRLbRDHA.2116@TK2MSFTNGP12.phx.gbl...
> Thanks for your prompt and exact help Alex. No more

NotSupportedExceptions.
> Brilliant.
>
> Now, when I ask for a URL of "http://server" (as per posted code), I get

a
> status of CONNMGR_STATUS_NOPATHTODESTINATION. ConnMgrMapURL returns a

valid
> GUID for this address.
> Yet when I enter this address into Pocket Internet Explorer, it correctly
> dials out.
> Same result if I try a URL of "http://www.microsoft.com".
>
> Have you (or others) any experience or thoughts on this one?
>
> Thanks again,
> Justin.
>
>
> "Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message
> news:%233ul3baRDHA.2148@TK2MSFTNGP10.phx.gbl...
> > Replace all instances of Long with Integer. Long is not supported by
> > marshaller and unlike VB6 it is 64bit integer. YOu need 32-bit, which is
> > type Integer
> >
> > "Justin Marshall" <hqtrainer@hotmail.com> wrote in message
> > news:eO0a5UaRDHA.2188@TK2MSFTNGP10.phx.gbl...
> > > Greetings,
> > >
> > > I am having difficulty calling the ConnMgrEstablishConnection function
> > > through PInvoke which I hope somebody can assist with.
> > > I have used the CMHelper project in the PPC2002SDK as a basis for this

> > code.
> > >
> > > The call to ConnMgrMapURL works fine, but when I try and call
> > > ConnMgrEstablishConnection (via the EstablishConnection function

below),
> I
> > > get a NotSupportedException.
> > > I suspect that it may be a problem with the ConnMgr_ConnectionInfo

> > structure
> > > (eg. data types). I had tried hWnd and lParam with Integer data type

as
> > well
> > > with the same effect.
> > >
> > > My call to ConnMgrConnectionStatus also achieves the same result but
> > > possibly because I do not have a valid handle.
> > >
> > > Thanks for any help anybody is able to provide.
> > >
> > > Regards,
> > > Justin Marshall.
> > >
> > >
> > >
> > > Following is the code I currently have (in VB.Net):
> > >
> > > '---------------------------------------------------------------------
> > > Imports System.Runtime.InteropServices
> > >
> > > Public Class CConnMgr
> > >
> > > Private m_lngConnectionHandle As Long
> > >
> > > Private Const CONNMGR_PARAM_GUIDDESTNET = 1 ' @constdefine

> guidDestNet
> > > field is valid
> > >
> > > Private Const CONNMGR_PARAM_MAXCONNLATENCY = 8 ' @constdefine
> > > MaxConnLatency field is valid
> > >
> > > Private Const CONNMGR_PRIORITY_USERINTERACTIVE = &H8000
> > >
> > > Public Const CONNMGR_STATUS_UNKNOWN = &H0 ' @constdefine Unknown

> > status
> > > Public Const CONNMGR_STATUS_CONNECTED = &H10 ' @constdefine

> Connection
> > > is up
> > > Public Const CONNMGR_STATUS_DISCONNECTED = &H20 ' @constdefine
> > > Connection is disconnected
> > > Public Const CONNMGR_STATUS_CONNECTIONFAILED = &H21 ' @constdefine
> > > Connection failed and cannot not be reestablished
> > > Public Const CONNMGR_STATUS_CONNECTIONCANCELED = &H22 '

@constdefine
> > > User aborted connection
> > > Public Const CONNMGR_STATUS_CONNECTIONDISABLED = &H23 '

@constdefine
> > > Connection is ready to connect but disabled
> > > Public Const CONNMGR_STATUS_NOPATHTODESTINATION = &H24 '

> @constdefine
> > No
> > > path could be found to destination
> > > Public Const CONNMGR_STATUS_WAITINGFORPATH = &H25 ' @constdefine

> > Waiting
> > > for a path to the destination
> > > Public Const CONNMGR_STATUS_WAITINGFORPHONE = &H26 ' @constdefine

> > Voice
> > > call is in progress
> > > Public Const CONNMGR_STATUS_WAITINGCONNECTION = &H40 '

@constdefine
> > > Attempting to connect
> > > Public Const CONNMGR_STATUS_WAITINGFORRESOURCE = &H41 '

@constdefine
> > > Resource is in use by another connection
> > > Public Const CONNMGR_STATUS_WAITINGFORNETWORK = &H42 '

@constdefine
> No
> > > path could be found to destination
> > > Public Const CONNMGR_STATUS_WAITINGDISCONNECTION = &H80 '

> @constdefine
> > > Connection is being brought down
> > > Public Const CONNMGR_STATUS_WAITINGCONNECTIONABORT = &H81 '

> > @constdefine
> > > Aborting connection attempt
> > >
> > > Public Structure ConnMgr_ConnectionInfo
> > > Public Size As Long
> > > Public Params As Long
> > > Public Flags As Long
> > > Public Priority As Long
> > >
> > > Public Exclusive As Boolean
> > > Public Disabled As Boolean
> > >
> > > Public DestNetGuid As Guid
> > >
> > > Public hWnd As IntPtr
> > > Public Msg As Integer
> > > Public lParam As IntPtr
> > >
> > > Public MaxCost As Long
> > > Public MinRcvBw As Long
> > > Public MaxConnLatency As Long
> > > End Structure
> > >
> > > <DllImport("cellcore.dll")> Private Shared Function
> > > ConnMgrEnumDestinations(ByVal DestIndex As Integer, ByRef DestInfo As
> > > ConnMgr_DestinationInfo) As Integer
> > > End Function
> > > <DllImport("cellcore.dll")> Private Shared Function
> > > ConnMgrEstablishConnection(ByRef ConnInfo As ConnMgr_ConnectionInfo,

> ByRef
> > > ConnHandle As Long) As Integer
> > > End Function
> > > <DllImport("cellcore.dll")> Private Shared Function
> > > ConnMgrEstablishConnectionSync(ByRef ConnInfo As

ConnMgr_ConnectionInfo,
> > > ByRef ConnHandle As Long, ByVal Timeout As Long, ByRef FinalStatus As

> > Long)
> > > As Integer
> > > End Function
> > > <DllImport("cellcore.dll")> Private Shared Function
> > > ConnMgrConnectionStatus(ByVal hConn As Long, ByRef iStatus As Long) As
> > > Integer
> > > End Function
> > > <DllImport("cellcore.dll")> Private Shared Function

> > ConnMgrMapURL(ByVal
> > > URL As String, ByRef NetworkGuid As Guid, ByRef GuidIndex As Long) As
> > > Integer
> > > End Function
> > > <DllImport("cellcore.dll")> Private Shared Function
> > > ConnMgrReleaseConnection(ByVal ConnHandle As Long, ByVal
> > > AllowConnectionToBeCached As Boolean) As Integer
> > > End Function
> > >
> > > Public Function GetNetworkFromPath(ByVal URL As String) As Guid
> > >
> > > Dim NetworkGuid As Guid
> > > Dim GuidIndex As Long
> > > Dim Result As Integer
> > >
> > > Result = ConnMgrMapURL(URL, NetworkGuid, GuidIndex)
> > >
> > > Return NetworkGuid
> > >
> > > End Function
> > >
> > > Public Function EstablishConnection() As Integer
> > >
> > > Dim ConnInfo As ConnMgr_ConnectionInfo
> > > Dim ConnHandle As Long
> > > Dim FinalStatus As Long
> > > Dim Result As Integer
> > >
> > > ConnInfo.Size = Marshal.SizeOf(ConnInfo)
> > > ConnInfo.Params = CONNMGR_PARAM_GUIDDESTNET Or
> > > CONNMGR_PARAM_MAXCONNLATENCY
> > > ConnInfo.Flags = 0
> > > ConnInfo.MaxConnLatency = 4000
> > > ConnInfo.Disabled = False
> > > ConnInfo.Priority = CONNMGR_PRIORITY_USERINTERACTIVE
> > > ConnInfo.DestNetGuid = GetNetworkFromPath("http://server")
> > >
> > > Try
> > > Result = ConnMgrEstablishConnectionSync(ConnInfo,

> ConnHandle,
> > > 4000, FinalStatus)
> > > m_lngConnectionHandle = ConnHandle
> > >
> > > MsgBox("Connection handle = " & ConnHandle.ToString)
> > >
> > > Catch ex As System.NotSupportedException
> > > MsgBox("NotSupportedError in EstablishConnection")
> > >
> > > Catch ex As Exception
> > > MsgBox("Error in EstablishConnection (" & ex.Message &

")")
> > >
> > > End Try
> > >
> > > End Function
> > >
> > > Public Function Status() As Integer
> > >
> > > Dim lngCurrentStatus As Long
> > > Dim intResult As Integer
> > >
> > > intResult = ConnMgrConnectionStatus(m_lngConnectionHandle,
> > > lngCurrentStatus)
> > >
> > > Return lngCurrentStatus
> > >
> > > End Function
> > >
> > > End Class
> > >
> > >

> >
> >

>
>



  Reply With Quote
Old 21-10-2005, 07:50 AM   #5
prerak_v_shah
Junior Member
 
Join Date: Oct 2005
Posts: 2
Trader Rating: (0)
Default Please send me sample code

Hi,

These days i stuck in the same thing, Can you please send me the code for establishing connection using Connection Manager API.

I mean please send me the final code you changed for making connection.

Thank
prerak_v_shah is offline   Reply With Quote
Old 19-09-2006, 07:03 AM   #6
vaid.mca
Junior Member
 
Join Date: Sep 2006
Posts: 1
Trader Rating: (0)
Default Source Code Required

Hi all There,

I am also working on the same project, for connecting to ftp site using RAS connection using pocket pc's internal modem.
Can you please send me the complete code for using connection manager for making RAS connection?

I will be highly thankful to you.

Please reply me at vaid.mca@gmail.com

thanks,

Sachin Vaid

Last edited by vaid.mca : 19-09-2006 at 07:06 AM.
vaid.mca is offline   Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off