CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2004
    Posts
    20

    Disconnect internet connection

    Hi,

    What is the classes or function which used to disconnect internet connection ???

    thanks

  2. #2
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: Disconnect internet connection

    What do U mean by "disconnect internet connection" ?

  3. #3
    Join Date
    Oct 2004
    Posts
    20

    Re: Disconnect internet connection

    I mean disconnect internet .

  4. #4
    Join Date
    Dec 2004
    Location
    Islamabad,Pakistan
    Posts
    71

    Re: Disconnect internet connection

    You can use WinINet ....
    Windows Internet Support it
    InternetHangUp
    can be used to disconnect from the internet.

  5. #5
    Join Date
    Oct 2004
    Posts
    20

    Re: Disconnect internet connection

    Thank you for your help

    the function is :

    DWORD InternetHangUp(
    DWORD dwConnection,
    DWORD dwReserved
    );


    can you give me an example explain how to ues it ???

  6. #6
    Join Date
    Dec 2004
    Location
    Islamabad,Pakistan
    Posts
    71

    Re: Disconnect internet connection

    try this .............




    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //BEGIN
    InternetConnectionState flags = 0;
    int nConnection = 0;
    bool bInternet = InternetGetConnectedState(ref flags,0);
    if (bInternet == false)
    {
    //Not Connected
    if (flags == 0)
    {
    //Do something to tell the user to install some internet connection
    }
    int nResult = InternetDial(IntPtr.Zero,"",(int)InternetDialFlags.INTERNET_DIAL_FORCE_PROMPT , ref nConnection , 0);
    switch(nResult)
    {
    case 87://Bad Parameter for InternetDial - Couldn't Connect";
    break;
    case 668://No Connection for InternetDial - Couldn't Connect";
    break;
    case 631://User Cancelled Dialup
    break;
    default://Unknown InternetDial Error
    break;
    case 0://Connection Succeeded
    break;
    }
    //Do whatever you need to do on the internet (send mail etc)
    InternetHangup(nConnection,0);
    //DONE
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    [DllImport("wininet.dll",CharSet=CharSet.Auto)]
    static extern bool InternetGetConnectedState(ref InternetConnectionState lpdwFlags, int dwReserved);
    [Flags]
    enum InternetConnectionState: int
    {
    INTERNET_CONNECTION_MODEM = 0x1,
    INTERNET_CONNECTION_LAN = 0x2,
    INTERNET_CONNECTION_PROXY = 0x4,
    INTERNET_RAS_INSTALLED = 0x10,
    INTERNET_CONNECTION_OFFLINE = 0x20,
    INTERNET_CONNECTION_CONFIGURED = 0x40
    }
    [DllImport("wininet.dll",CharSet=CharSet.Auto)]
    static extern int InternetDial(IntPtr hwndParent,[MarshalAs(UnmanagedType.LPStr)] string strConnection,[MarshalAs(UnmanagedType.U4)]int dwFlags,ref int dwConnection,int dwReserved);
    [Flags]
    enum InternetDialFlags: int
    {
    INTERNET_DIAL_FORCE_PROMPT =0x2000,
    INTERNET_DIAL_SHOW_OFFLINE =0x4000,
    INTERNET_DIAL_UNATTENDED =0x8000
    }
    [DllImport("wininet.dll",CharSet=CharSet.Auto)]
    static extern int InternetHangup([MarshalAs(UnmanagedType.U4)] int nConnection,[MarshalAs(UnmanagedType.U4)]int dwReserved);

  7. #7
    Join Date
    Oct 2004
    Posts
    20

    Re: Disconnect internet connection

    Thank you ,

    I try to write the statements which you give , but there is an error :

    "Unable to find an entry point named InternetHangup in DLL wininet.dll".

    and reject to disconnect the internet , i donn't understand what is it

    thank you for your help.

  8. #8
    Join Date
    Dec 2004
    Location
    Islamabad,Pakistan
    Posts
    71

    Re: Disconnect internet connection

    Hi,


    There may be problem with wininet.dll, and i think the problem is of versions...you can search the internet for solving this problem... i hope you will put your self back with GOOGLE.


    thanks
    Usman,
    Islamabad, Pakistan

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