Click here to Skip to main content
15,895,606 members
Home / Discussions / C#
   

C#

 
AnswerRe: abstract class constructor? Pin
Niklas Ulvinge2-Sep-05 10:39
Niklas Ulvinge2-Sep-05 10:39 
AnswerRe: abstract class constructor? Pin
ediazc2-Sep-05 13:31
ediazc2-Sep-05 13:31 
GeneralRe: abstract class constructor? Pin
Niklas Ulvinge2-Sep-05 21:44
Niklas Ulvinge2-Sep-05 21:44 
QuestionCasting to double Pin
Goebel2-Sep-05 9:29
Goebel2-Sep-05 9:29 
AnswerRe: Casting to double Pin
Alomgir Miah2-Sep-05 10:00
Alomgir Miah2-Sep-05 10:00 
AnswerRe: Casting to double Pin
Guffa2-Sep-05 10:44
Guffa2-Sep-05 10:44 
GeneralRe: Casting to double Pin
Goebel2-Sep-05 23:45
Goebel2-Sep-05 23:45 
GeneralInternet Dial from C# Pin
Member 22453512-Sep-05 9:20
Member 22453512-Sep-05 9:20 
Here is a class to dial, hangup, and test the internet connection being used.

Paul R. Johnson

using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
namespace ComServer_Business_Logic
{
public class Dialer
{

[System.Runtime.InteropServices.DllImport("wininet.dll", EntryPoint="InternetGetConnectedState", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
private static extern bool InternetGetConnectedState(ref Int32 lpdwFlags, Int32 dwReserved);

[System.Runtime.InteropServices.DllImport("Wininet.dll", EntryPoint="InternetDial", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
private static extern Int32 InternetDial(IntPtr hwndParent, string lpszConnectoid, Int32 dwFlags, ref Int32 lpdwConnection, Int32 dwReserved);

[System.Runtime.InteropServices.DllImport("Wininet.dll", EntryPoint="InternetHangUp", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
private static extern Int32 InternetHangUp(Int32 lpdwConnection, Int32 dwReserved);

private enum Flags: int
{
//Local system uses a LAN to connect to the Internet.
INTERNET_CONNECTION_LAN = 0X2,
//Local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM = 0X1,
//Local system uses a proxy server to connect to the Internet.
INTERNET_CONNECTION_PROXY = 0X4,
//Type Visual Basic 6 code here...

//Local system has RAS installed.
INTERNET_RAS_INSTALLED = 0X10
}

//Declaration Used For InternetDialUp.
private enum DialUpOptions: int
{
INTERNET_DIAL_UNATTENDED = 0X8000,
INTERNET_DIAL_SHOW_OFFLINE = 0X4000,
INTERNET_DIAL_FORCE_PROMPT = 0X2000
}

private const int ERROR_SUCCESS = 0X0;
private const int ERROR_INVALID_PARAMETER = 0X87;


private Int32 mlConnection;

public string GetConnectionType()
{
Int32 lngFlags = 0;

if (InternetGetConnectedState(ref lngFlags, 0))
{
//connected.
if ((lngFlags & (int)Flags.INTERNET_CONNECTION_LAN)!=0)
{
//LAN connection.
return "LAN connection.";
}
else if ((lngFlags & (int)Flags.INTERNET_CONNECTION_MODEM)!=0)
{
//Modem connection.
return "Modem connection.";
}
else if ((lngFlags & (int)Flags.INTERNET_CONNECTION_PROXY)!=0)
{
//Proxy connection.
return "Proxy connection.";
}
return "Not connected.";
}
else
{
//not connected.
return "Not connected.";
}
}
public void Connect()
{
Int32 DResult = 0;

DResult = InternetDial(IntPtr.Zero, "My Connection", Convert.ToInt32(DialUpOptions.INTERNET_DIAL_UNATTENDED), ref mlConnection, 0);

if (DResult == ERROR_SUCCESS)
Console.WriteLine("Dial Up Successful");
else
Console.WriteLine("UnSuccessFull Error Code");
}
public void Disconnect()
{
Int32 Result = 0;

if (! (mlConnection == 0))
{
Result = InternetHangUp(mlConnection, 0);
if (Result == 0)
Console.WriteLine("Hang up successful");
else
Console.WriteLine("Hang up NOT successful");
}
else
Console.WriteLine("You must dial a connection first!");
}
}

}
GeneralRe: Internet Dial from C# Pin
Dan Neely2-Sep-05 10:10
Dan Neely2-Sep-05 10:10 
GeneralRe: Internet Dial from C# Pin
Member 22453516-Sep-05 3:02
Member 22453516-Sep-05 3:02 
Questionhelp me plz Pin
jaws_bodo2-Sep-05 9:17
sussjaws_bodo2-Sep-05 9:17 
AnswerRe: help me plz Pin
Dan Neely2-Sep-05 10:14
Dan Neely2-Sep-05 10:14 
GeneralRe: help me plz Pin
Dave Shaw2-Sep-05 13:18
Dave Shaw2-Sep-05 13:18 
GeneralRe: help me plz Pin
Anonymous6-Sep-05 22:53
Anonymous6-Sep-05 22:53 
QuestionInsert Fails W/Unique Constraint Pin
rich_wenger2-Sep-05 9:09
rich_wenger2-Sep-05 9:09 
AnswerRe: Insert Fails W/Unique Constraint Pin
Mohamad Al Husseiny2-Sep-05 14:53
Mohamad Al Husseiny2-Sep-05 14:53 
QuestionRegular Expression Pin
Derick Cyril Thomas2-Sep-05 8:17
Derick Cyril Thomas2-Sep-05 8:17 
AnswerRe: Regular Expression Pin
Guffa2-Sep-05 8:32
Guffa2-Sep-05 8:32 
AnswerRe: Regular Expression Pin
Alomgir Miah2-Sep-05 9:18
Alomgir Miah2-Sep-05 9:18 
QuestionDataGridView has no CaptionText or Title property Pin
billoo2-Sep-05 8:00
billoo2-Sep-05 8:00 
Questionget text from ie address bar Pin
qsosoq20002-Sep-05 7:33
qsosoq20002-Sep-05 7:33 
Questionoverride ToString() for Combobox Pin
PHDENG812-Sep-05 6:53
PHDENG812-Sep-05 6:53 
AnswerRe: override ToString() for Combobox Pin
Guffa2-Sep-05 7:11
Guffa2-Sep-05 7:11 
GeneralRe: override ToString() for Combobox Pin
PHDENG812-Sep-05 7:20
PHDENG812-Sep-05 7:20 
QuestionComboBox Mayhem Frustration. Pin
rich_wenger2-Sep-05 5:02
rich_wenger2-Sep-05 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.