 |
|
|
You opend a new window to internet connection(and RAS) for me!
Thanks.
---------------Signature--------------- I don't have Time To waste The Time!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, Can anyone help me in communicating with a device through dial up connection (c#.net). I am new to this field but i knew that we have to use RAS. I searched for sample codes, but not clear. I will be more thankful if I am given some sample source codes with explanation. Thanks in advance. Satheesh.
|
| Sign In·View Thread·PermaLink | 2.75/5 (4 votes) |
|
|
|
 |
|
|
When I translate the code it does not work when the call is made to RasEnumEntries Function: Here is the code:
Imports System.Runtime.InteropServices Namespace Utilities.Dialup.RAS
Public Enum RasFieldSizeConstants RAS_MaxDeviceType = 16 RAS_MaxPhoneNumber = 128 RAS_MaxIpAddress = 15 RAS_MaxIpxAddress = 21 #If WINVER4 Then RAS_MaxEntryName =256 RAS_MaxDeviceName =128 RAS_MaxCallbackNumber =RAS_MaxPhoneNumber #Else RAS_MaxEntryName = 20 RAS_MaxDeviceName = 32 RAS_MaxCallbackNumber = 48 #End If
RAS_MaxAreaCode = 10 RAS_MaxPadType = 32 RAS_MaxX25Address = 200 RAS_MaxFacilities = 200 RAS_MaxUserData = 200 RAS_MaxReplyMessage = 1024 RAS_MaxDnsSuffix = 256 UNLEN = 256 PWLEN = 256 DNLEN = 15 End Enum
_ Public Structure GUID Public Data1 As UInteger Public Data2 As UShort Public Data3 As UShort _ Public Data4() As Byte
End Structure
_ Public Structure RASCONN Public dwSize As Integer Public hrasconn As IntPtr _ Public szEntryName As String _ Public szDeviceType As String _ Public szDeviceName As String 'MAX_PAPTH=260 _ Public szPhonebook As String Public dwSubEntry As Integer Public guidEntry As GUID #If (WINVER501) Then Public dwFlags AS integer Public luid AS LUID #End If End Structure
_ Public Structure LUID Dim LowPart As Integer Dim HighPart As Integer End Structure
_ Public Structure RasEntryName Public dwSize As Integer _ Public szEntryName As String #If WINVER5 Then public dwFlags as Integer _ Public szPhonebookPath as String #End If End Structure
_ Public Class RasStats Public dwSize As Integer = Marshal.SizeOf(GetType(RasStats)) Public dwBytesXmited As Integer Public dwBytesRcved As Integer Public dwFramesXmited As Integer Public dwFramesRcved As Integer Public dwCrcErr As Integer Public dwTimeoutErr As Integer Public dwAlignmentErr As Integer Public dwHardwareOverrunErr As Integer Public dwFramingErr As Integer Public dwBufferOverrunErr As Integer Public dwCompressionRatioIn As Integer Public dwCompressionRatioOut As Integer Public dwBps As Integer Public dwConnectDuration As Integer End Class
Public Class RAS
Sub New()
End Sub
_ Public Shared Function RasEnumConnections( _ ByRef lprasconn As RASCONN _ , ByRef lpcb As Integer _ , ByRef lpcConnections As Integer _ ) As Integer
End Function
''' ''' ''' ''' handle to the connection ''' buffer to receive statistics ''' ''' _ Public Shared Function RasGetConnectionStatistics( _ ByVal hRasConn As IntPtr _ , ByRef lpStatistics As RasStats _ ) As UInteger
End Function
''' ''' ''' ''' handle to the RAS connection to hang up ''' ''' _ Public Shared Function RasHangUp( _ ByVal hrasconn As IntPtr _ ) As UInteger
End Function
''' ''' ''' ''' reserved, must be NULL ''' pointer to full path and file name of phone-book file ''' buffer to receive phone-book entries ''' size in bytes of buffer ''' number of entries written to buffer ''' ''' _ Public Shared Function RasEnumEntries( _ ByVal reserved As String, _ ByVal lpszPhonebook As String, _ ByRef lprasentryname As RasEntryName(), _ ByRef lpcb As Integer, _ ByRef lpcEntries As Integer _ ) As UInteger End Function
_ Public Shared Function InternetDial( _ ByVal hwnd As IntPtr, _ ByVal lpszConnectoid As String, _ ByVal dwFlags As UInteger, _ ByRef lpdwConnection As Integer, _ ByVal dwReserved As UInteger _ ) As Integer End Function
End Class
Public Class RASDisplay Private m_duration As String Private m_ConnectionName As String Private m_ConnectionNames() As String Private m_TX As Double Private m_RX As Double Private m_connected As Boolean Private m_ConnectedRasHandle As IntPtr
Sub New() m_connected = True
Dim lpras As RAS = New RAS Dim lprasConn As RASCONN = New RASCONN
lprasConn.dwSize = Marshal.SizeOf(GetType(RASCONN)) lprasConn.hrasconn = IntPtr.Zero
Dim lpcb As Integer = 0 Dim lpcConnections As Integer = 0 Dim nRet As Integer = 0 lpcb = Marshal.SizeOf(GetType(RASCONN))
nRet = RAS.RasEnumConnections(lprasConn, lpcb, lpcConnections)
If nRet <> 0 Then m_connected = False Return End If
If lpcConnections > 0 Then
Dim stats As RasStats = New RasStats m_ConnectedRasHandle = lprasConn.hrasconn RAS.RasGetConnectionStatistics(lprasConn.hrasconn, stats)
m_ConnectionName = lprasConn.szEntryName
Dim Hours As Integer = 0 Dim Minutes As Integer = 0 Dim Seconds As Integer = 0
Hours = ((stats.dwConnectDuration / 1000) / 3600) Minutes = ((stats.dwConnectDuration / 1000) / 60) - (Hours * 60) Seconds = ((stats.dwConnectDuration / 1000)) - (Minutes * 60) - (Hours * 3600)
m_duration = Hours + " hours " + Minutes + " minutes " + Seconds + " secs" m_TX = stats.dwBytesXmited m_RX = stats.dwBytesRcved
Else m_connected = False End If
Dim lpNames As Integer = 1 Dim entryNameSize As Integer = 0 Dim lpSize As Integer = 0 Dim names() As RasEntryName
entryNameSize = Marshal.SizeOf(GetType(RasEntryName)) lpSize = lpNames * entryNameSize
ReDim names(lpNames - 1) names(0).dwSize = entryNameSize
Dim retval As UInteger = RAS.RasEnumEntries(Nothing, Nothing, names, lpSize, lpNames)
' if we have more than one connection, we need to do it again If lpNames > 1 Then ReDim names(lpNames) For i As Integer = 0 To names.Length - 1 names(0).dwSize = entryNameSize Next retval = RAS.RasEnumEntries(Nothing, Nothing, names, lpSize, lpNames)
End If ReDim m_ConnectionNames(names.Length)
If lpNames > 0 Then For i As Integer = 0 To names.Length - 1 m_ConnectionNames(i) = names(i).szEntryName Next End If End Sub
Public ReadOnly Property Duration() As String Get Return IIf(m_connected, m_duration, "") End Get End Property
Public ReadOnly Property Connections() As String() Get Return m_ConnectionNames End Get End Property
Public ReadOnly Property BytesTransmitted() As Double Get Return IIf(m_connected, m_TX, 0) End Get End Property
Public ReadOnly Property BytesReceived() As Double Get Return IIf(m_connected, m_RX, 0) End Get End Property
Public ReadOnly Property ConnectionName() As String Get Return IIf(m_connected, m_ConnectionName, "") End Get End Property
Public ReadOnly Property IsConnected() As Boolean Get Return m_connected End Get End Property
Public Function Connect(ByVal connection As String) As Integer Dim temp As Integer = 0 Dim INTERNET_AUTO_DIAL_UNATTENDED As UInteger = 2 Dim retVal As Integer = RAS.InternetDial(IntPtr.Zero, connection, INTERNET_AUTO_DIAL_UNATTENDED, temp, 0) Return retVal End Function
Public Sub Disonnect(ByVal connection As String) RAS.RasHangUp(m_ConnectedRasHandle) End Sub
End Class
End Namespace
Appreciate any help posible
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Hi there, Can anyone please tell me why I cant disconnect or even get ANY exception out of this code..
private void btnDisconnect_Click(object sender, EventArgs e) { try { IntPtr m_ConnectedRasHandle; RASCONN lprasConn = new RASCONN();
m_ConnectedRasHandle = lprasConn.hrasconn; RAS.RasHangUp(m_ConnectedRasHandle); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
Thanx a bunch guyz
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
In my system using this code i can not get the duration time for a connection. could anyone get the duration info ??
thanx for the code
Shahab
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
When I execute the following piece of code:
RASDisplay rc = new RASDisplay(); rc.Connect(rc.Connections[0]);
There is a window displaying the progress of dialing. How can I eliminate this window?
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
If I try to connect with a certain providers, I obtain error 691. That error says: "Access denied because username and/or password is invalid on the domain. " Why I obtain this error ??? I saved password's connections, and the user/password is correct.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
I just need a command line app, but I can't seem to get the Connected method to fire. As you may suspect, I'm pretty new to C#.
I have the RAS assembly registered, and referenced from my command prompt project. It dials, but the rasConn_Connected() method never fires, and that's where I want to do the work.
any help would be fabulous.....
===========================================================
using System; using System.ComponentModel; using System.Collections; using System.Diagnostics; using System.ComponentModel.Design; using System.Runtime.InteropServices; using System.Runtime; using System.Threading; using System.Reflection; using System.Resources; using Ras;
namespace trconlyget { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. /// /// private Ras.RasConnection rasConn; private RasConnection[] _RasConns; private RasEntry[] _RasEntrys; private bool _FlashFlag; private Ras.RasConnectionNotify rcnNotify;
public Class1() { //Console.WriteLine("Hello"); }
static void Main(string[] args) { Class1 cls = new Class1(); cls.rasConn = new Ras.RasConnection("Number","ID,"PASSWORD",""); cls.rasConn.Connected += new EventHandler(cls.rasConn_Connected); cls.rasConn.Dial(); }
public void rasConn_Connected(object sender, System.EventArgs e) { // This method never fires. Console.WriteLine("Connected"); } } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
HI, I have jsut successfully completed a small project using your dial-up code as starting point. Tanks. It worked well
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
I always have the error number 632 when calling the RasEnumConnections function. The error (ID : ERROR_INVALID_SIZE) described in raserror.h says : " An incorrect structure size was detected. " I think it concerns the RASCONN structure. So, I've tried all the #define WINVER(0x500, 0x400, ...), but the problem persits.
Can anybody help me about his ?
Thnk you very very much.
|
| Sign In·View Thread·PermaLink | 2.67/5 (3 votes) |
|
|
|
 |
|
|
I too have the same problem. It is urgent can any body help me out.
Thanks Ramesh rameshreddy.keesara@gmail.com
swprofessional
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thank you for this work, but i have a problem with win98. i try to show the RAS connections in a combobox, but it seems that your code can't see these connections. The Connections Property of RASDisplay is always empty. On a XP machine it works perfectly. Can you help me please. Does win98 handle the connections by an other way?
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
Hi,
thank you for you job. I worked on it all the day, and two questions came in my brain : - how is it poossible to have more than one connection ? - I would prefer to use RasDial instead of InternetDial because it provides a handle on the RASCONN structure. But, how can I translate from C++ to C# the CALLBACK macro required when specifying the RasDialFunction argument ?
Thank you.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, This is one of the excellent source codes in a RAS that I've ever come across.But the problem is, when the "RAS.InternetDial" is called, the Dial-up configuration Form pops up.I donot want to show up this form.I also need the control to return to the calling program, when connection is not established after 3 retries.
Would be grateful if you could help me. Thanks, Arun.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
hi i am making application with c# which need to dial to internet, i used c++ApI, i have a problem with InternetDial() function because it make dial with default connection on pc, but iwant to make it connect with numbers from data base so iwant to get the number it dial with please help
|
| Sign In·View Thread·PermaLink | 1.33/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
DataGrid with id 'dgAllConnections' could not automatically generate any columns from the selected data source. Thanks Keep up the good work
|
| Sign In·View Thread·PermaLink | 1.75/5 (3 votes) |
|
|
|
 |
|
|
Hi
While I really do appreciate the functionality of the code, I find it quite unstructered. Personally I would have preferred a clear separation of the code into 2 classes: An inner class, which implements the core dialup code. And an outer class, wrapping the inner class, but adding the statistics code.
Well, enough about that .
A critical error arises if you do not create different objects for connecting and disconnecting the modem : The modem will never disconnect! Example:
RasDisplay rasDisplay = new RasDisplay(); rasDisplay.Connect(rasDisplay.ConnectionName); //standard dialup
//some code here, eg. a webservice call or something
rasDisplay.Disconnect(); //this fails!!!
//workaround : create a new object, never reuse the old. rasDisplay = new RasDisplay(); rasDisplay.Disconnect(); //this works
The problem can be solved correctly by rewriting the Connect method : The m_ConnectedRasHandle has to be set.
But THANKS for the hard work 
Kind regards, Rasmus, Denmark
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I've found another error that you might want to correct:
Line 243 in RAS.cs should be: m_ConnectionNames = new string[lpNames];
Instead of: m_ConnectionNames = new string[names.Length];
This error shows when you have no (0) connections available. If so, the length of m_ConnectionNames is still 1, indicating that a connection exists. If you try to dialup this non-existing connection, the program freezes.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Is it possible to create an event that will detect if the connection has been disconnected?
"To teach is to learn twice"
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|