
E-mail & Modem Internet Conection Detection
Quote:
> OTSER wrote :
> > > [...] How can I detect when the modem starts the dial up
> > > connection ? (when this serial sound starts)
RAS.
The following code was downloaded and modified by me. Here's the header from the
orignal.
' http://matthart.com
'
' This sample shows how to fire up a DUN (Dial Up Networking)
' connection and see if it is online. There are a lot more
' API functions available in the RAS API. You can download an excellent
' sample program from Microsoft called VB32RAS.EXE at:
' http://support.microsoft.com/support/downloads/dp2109.asp
'
' Christian Gustavo Riva gave me the NT dial version. Thanks Christian!
I'm using this to display the list of defined DUN connections (called Entries in
RAS),
connect to them thru program. I allow user to connect directly (from Explorer
for e.g.)
and still can capture that (using a timer with DUNConnected()); I display the
name
of connection actually used by user in that case.
Thanks, Matt. Powerful, short and cool. If you're listening, do I really need to
handle Win9X vs WinNT? How do I do that?
--
MikeC
Please reply to the group.
--------------------------------------
Option Explicit
Private Const RAS_MaxDeviceType = 16
Private Const RAS95_MaxDeviceName = 128
Private Const RAS95_MaxEntryName = 256
Private Type RASCONN95
' Set dwsize to 412.
dwSize As Long
hRasConn As Long
szEntryName(RAS95_MaxEntryName) As Byte
szDeviceType(RAS_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Private Type RASDEVINFO
dwSize As Long
szDeviceType(RAS_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Private Type RASENTRYNAME95
' Set dwsize to 264.
dwSize As Long
szEntryName(RAS95_MaxEntryName) As Byte
End Type
Private Declare Function RasEnumConnections Lib "RasApi32.DLL" Alias
"RasEnumConnectionsA" (lpRASConn As Any, lpCB As Long, lpcConnections As Long)
As Long
Private Declare Function RasEnumDevices Lib "RasApi32.DLL" Alias
"RasEnumDevicesA" (lprasdevinfo As Any, lpCB As Long, lpcConnections As Long) As
Long
Private Declare Function RasEnumEntries Lib "RasApi32.DLL" Alias
"RasEnumEntriesA" (ByVal Reserved As String, ByVal lpszPhonebook As String,
lpRASEntryName As Any, lpCB As Long, lpcEntries As Long) As Long
Public Sub DUNConnect(ByVal sConnection As String)
Dim sCommand As String
sCommand = "rundll rnaui.dll,RnaDial " & sConnection
' NT Version
' sCommand = "rasphone.exe " & Chr$(34) & sconnection & Chr$(34)
Shell sCommand, vbNormalFocus
End Sub
Public Function DUNConnected(ByRef lbAny As ListBox) As String
Dim lBufferSize As Long
Dim l As Long
Dim i As Long
ReDim aDUNConnectionList(0 To 255) As RASCONN95
Dim lCount As Long
Dim sConnection As String
aDUNConnectionList(0).dwSize = LenB(aDUNConnectionList(0)) '412
lBufferSize = (UBound(aDUNConnectionList) - LBound(aDUNConnectionList) + 1)
* aDUNConnectionList(0).dwSize
l = RasEnumConnections(aDUNConnectionList(0), lBufferSize, lCount)
For l = 0 To lCount - 1
sConnection = StrConv(aDUNConnectionList(l).szEntryName(), vbUnicode)
sConnection = Left$(sConnection, InStr(sConnection, Chr$(0)) - 1)
For i = 0 To lbAny.ListCount - 1
If sConnection = lbAny.List(i) Then
DUNConnected = sConnection
End If
Next
Next
End Function
Public Sub DUNLoadEntryList(ByRef lbAny As ListBox)
Dim lBufferSize As Long
Dim l As Long
ReDim aDUNEntries(0 To 255) As RASENTRYNAME95
Dim lCount As Long
Dim sEntry As String
aDUNEntries(0).dwSize = LenB(aDUNEntries(0)) '264
lBufferSize = (UBound(aDUNEntries) - LBound(aDUNEntries) + 1) *
aDUNEntries(0).dwSize
l = RasEnumEntries(vbNullString, vbNullString, aDUNEntries(0), lBufferSize,
lCount)
For l = 0 To lCount - 1
sEntry = StrConv(aDUNEntries(l).szEntryName(), vbUnicode)
lbAny.AddItem Left$(sEntry, InStr(sEntry, vbNullChar) - 1)
Next
If (lbAny.ListCount > 0) Then
lbAny.ListIndex = 0
End If
End Sub