Results 1 to 7 of 7

Thread: What am I doing wrong?

  1. #1

    Thread Starter
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    To check to see if there is a DUN I use one of two ways

    1:
    Code:
    Public Declare Function InternetGetConnectedState _
    Lib "wininet.dll" (ByRef lpSFlags As Long, _
    ByVal dwReserved As Long) As Long
    
    Public Const INTERNET_CONNECTION_MODEM As Long = &H1
    
    Public Function ViaModem() As Boolean
    
    Dim SFlags As Long
    
    Call InternetGetConnectedState(SFlags, 0&)
    
    ViaModem = SFlags And INTERNET_CONNECTION_MODEM
    
    End Function
    Now this works fine in win98 and win95. However it always returns true in WinME??!?? Thank you microsoft!

    So I tried this method:
    2.
    Code:
    Public Const ERROR_SUCCESS = 0&
    Public Const APINULL = 0&
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public ReturnCode As Long
    
    Declare Function RegCloseKey Lib "advapi32.dll" (ByVal _
    hKey As Long) As Long
    
    Declare Function RegOpenKey Lib "advapi32.dll" Alias _
    "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
    String, phkResult As Long) As Long
    
    Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
    "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName _
    As String, ByVal lpReserved As Long, lpType As Long, _
    lpData As Any, lpcbData As Long) As Long
    
    Public Function ActiveConnection() As Boolean
    Dim hKey As Long
    Dim lpSubKey As String
    Dim phkResult As Long
    Dim lpValueName As String
    Dim lpReserved As Long
    Dim lpType As Long
    Dim lpData As Long
    Dim lpcbData As Long
    ActiveConnection = False
    lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
    ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, _
    phkResult)
    
    If ReturnCode = ERROR_SUCCESS Then
        hKey = phkResult
        lpValueName = "Remote Connection"
        lpReserved = APINULL
        lpType = APINULL
        lpData = APINULL
        lpcbData = APINULL
        ReturnCode = RegQueryValueEx(hKey, lpValueName, _
        lpReserved, lpType, ByVal lpData, lpcbData)
        lpcbData = Len(lpData)
        ReturnCode = RegQueryValueEx(hKey, lpValueName, _
        lpReserved, lpType, lpData, lpcbData)
        
        If ReturnCode = ERROR_SUCCESS Then
            If lpData = 0 Then
                ActiveConnection = False
            Else
                ActiveConnection = True
            End If
        End If
    RegCloseKey (hKey)
    End If
    
    End Function
    This also works fine except if the computer is reset while there was an internet connection. When the machine boots it always returns true until a new internet connection is astablished and disconnected.

    Any ideas?

    If it's possible to check the modem status i.e. dialling, connection, etc that will also be fine.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Click Me
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    Thanks HeSaidJoe. Unfortunately some people use 9600bps modems and I need to check quickly. Any other ideas?

  4. #4
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    A modem should use one of the COM ports right? How about checking the status of the port using the MSCOMM control in a regular time interval?

    [Edited by shafee on 11-17-2000 at 04:10 PM]

  5. #5

    Thread Starter
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    Ok. Found the problem. If a network card is installed number 1 always returns true. Otherwise it works fine. What the hell has a network card got to do with the current connection status of a modem??????

  6. #6
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305
    that might be because most computers that are networked are networked not only to share resources such as printers but also the internet connection

  7. #7

    Thread Starter
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    Ok. Back to the first one. I changed the declaration to this:

    Code:
    Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Long, ByVal dwReserved As Long) As Long
    This method works. Thanks for your help guys.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width