using System;
using System.Collections;
using Microsoft.Win32;
using System.Runtime.InteropServices;

namespace LLNet.Utils
{
	public class Dial
	{
		const int INTERNET_CONNECTION_MODEM = 1; 
		const int INTERNET_CONNECTION_LAN = 2; 
		const int INTERNET_CONNECTION_PROXY = 4; 
		const int INTERNET_CONNECTION_MODEM_BUSY = 8; 

		public const int INTERNET_DIAL_UNATTENDED = 0x8000; 

		const int INTERNET_AUTODIAL_FORCE_ONLINE = 1; 
		const int INTERNET_AUTODIAL_FORCE_UNATTENDED = 2; 
		const int INTERNET_AUTODIAL_FAILIFSECURITYCHECK = 4; 

		private int m_mlConnection;


		[DllImport("wininet.dll")] 
		private extern static int InternetDial(IntPtr hwndParent,string lpszConnectoid,int dwFlags, out int lpdwConnection,int dwReserved); 
	
		//Creating the extern function...
		[DllImport("wininet.dll")]
		private extern static bool InternetGetConnectedState( out int Description, int ReservedValue ) ;

		[DllImport("wininet.dll")] 
		private extern static int InternetHangUp(int lpdwConnection, int ReservedValue );

		//Creating a function that uses the API function...
		public bool IsConnectedToInternet( )
		{
			int Desc ;
			return InternetGetConnectedState( out Desc, 0 ) ;

		}

		public int HangUp(string p_connectionName)
		{
			return InternetHangUp(m_mlConnection,0);
		}

		public int DialUp(string p_connectionName)
		{ 
			m_mlConnection = 0;
			//This is part of code that we are using for call InternetDial 
			int zez = InternetDial(IntPtr.Zero,p_connectionName,INTERNET_DIAL_UNATTENDED,out m_mlConnection,0);
			return zez;
		}
	}
}