CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 1999
    Posts
    4

    How to properly use dll in VB6

    Hi,
    My application is using VB6. I want to check if
    the PC is connect to internet.

    My code is:

    Public Declare Function InternetGetConnectedState Lib "wininet.dll" (lpdwFlags
    as Long, byval dwReserved as Long) as Boolean
    Dim ll as long
    Dim ret as Boolean
    ret = InternetGetConnectedState(ll, 0)
    Msgbox INTERNET_CONNECTION_LAN


    ret is always False.
    and more I want to see what value INTERNET_CONNECTION_LAN is.

    Msgbox INTERNET_CONNECTION_LAN
    display nothing. Then I try this

    Public Declare Function InternetAttemptConnect _
    Lib "wininet" (ByVal dwReserved As Integer) As Integer
    dim ss
    ss=InternetAttemptConnect(0),

    it return nothing too. If I need include some others?


    Thanks
    zys


  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: How to properly use dll in VB6

    DOcs say InternetAttemptConnect returns ERROR_SUCCESS on success. i.e Non-zero return value means Error, while 0 is success. {IN WinError.h ERROR_SUCCESS is #def to zero.}

    RK

  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: How to properly use dll in VB6

    the following code has been tested in NT 4 , VB 6

    option Explicit
    private Declare Function InternetGetConnectedState Lib "wininet" _
    (byref lState as Long, byval lRes as Long) as Long

    Const INTERNET_CONNECTION_MODEM = 1
    Const INTERNET_CONNECTION_LAN = 2
    Const INTERNET_CONNECTION_PROXY = 4
    Const INTERNET_CONNECTION_MODEM_BUSY = 8


    private Sub Command1_Click()
    Dim lState as Long
    Dim l as Long
    l = InternetGetConnectedState(lState, 0&)
    If l <> 0 then
    ' connected
    If lState And INTERNET_CONNECTION_PROXY then
    MsgBox "connected via proxy"
    End If
    End If
    End Sub





  4. #4
    Join Date
    Aug 1999
    Posts
    4

    Re: How to properly use dll in VB6

    Hi,
    Thanks

    I copy your code to my app in Win95.
    l = InternetGetConnectedState(lState, 0&)
    return value l is always <> 0 whatever I plug LAN line in or out.
    So I'm fail to check if user is online(even if he doesn't
    open browser).

    Maybe the concept of connection to internet is different?
    What I mean PC not connect to internet is user is not turn on
    his Modem or plug out his LAN line.


    Thanks again.
    yansong



  5. #5
    Join Date
    Aug 1999
    Posts
    4

    Re: How to properly use dll in VB6

    Hi,

    Dim lState As Long
    Dim l As Long
    l = InternetGetConnectedState(lState, 0&)
    If l <> 0 Then
    MsgBox "on line:" + CStr(l)
    ' connected
    If lState And INTERNET_CONNECTION_PROXY Then
    MsgBox "connected via proxy"
    End If
    If lState And INTERNET_CONNECTION_LAN Then
    MsgBox "connected via LAN"
    End If
    Else
    MsgBox "off line"
    End If


    Result is
    online:1
    But I do disconnect internet and use LAN not
    MODEM. Why?

    yansong




  6. #6
    Join Date
    May 1999
    Posts
    3,332

    Re: How to properly use dll in VB6

    I'm note sure what you are trying to accomplish.
    Facts are:
    - InternetGetConnectedState does not give you reliable information whether you are connected to the Internet or not
    - the only way that I know of to check if you have access to the internet is by retrieving a page from the internet. This can be done via the internet transfer control and its OpenURL method


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

Featured