/// <summary> /// Changes the RasDialParams of a phone-book entry. /// </summary> public void SetDialParams(RasDialParams dParams) { dParams.EntryName = this.Name; dParams.Update(); }
/// <summary> /// Dials the RAS connection. /// </summary> /// <param name="rasDialParams">Intelliprog.Ras.RasDialParams that includes all values for the RAS connection to dial.</param> /// <param name="bAsync">Specifies how-to dial connection synchronously or asynchronously.</param> /// <returns> RasError.Success if there was success.</returns> public RasError Dial(bool bAsync, RasDialParams rasDialParams) { uint flag = 0xFFFFFFFF; if (bDialing) //don't allow to dial if we are already dialing return RasError.DialAlreadyInProgress; if (rasDialParams == null) { rasDialParams = new RasDialParams(this.Name); } m_connectionHandle = 0; RasError ret = 0; bDialing = true; if (bAsync) { m_callbackWindow = new MessageHook(this); ret = Native.RasDial(IntPtr.Zero, null, rasDialParams.Data, flag, m_callbackWindow.Hwnd, ref m_connectionHandle); bDialing = false; } else { ret = Native.RasDial(IntPtr.Zero, null, rasDialParams.Data, 0, IntPtr.Zero, ref m_connectionHandle); bDialing = false; } return ret; }
/// <summary> /// Returns the RasDialParams of a phone-book entry. /// </summary> public RasDialParams GetDialParams() { // create the params RasDialParams dialParams = new RasDialParams(this.Name); // fill dialParams.GetData(); return dialParams; }
/// <summary> /// Creates a new RasEntry (phone-book entry). /// </summary> /// <param name="newEntry">RasEntry that contains all phone-book entry information.</param> /// <param name="dialParams">RasDialParams that contains dial parameters.</param> public static RasEntry CreateEntry(RasEntry newEntry, RasDialParams dialParams) { Native.Error ret = Native.Error.Success; int cbEntry = 0, cbDevCfg = 0; if (newEntry.DeviceType == "" || newEntry.DeviceName == "") { throw new Exception("DeviceName and DeviceType must be populated in the RasEntry."); } //validate entry first ret = Native.RasValidateEntryName(null, newEntry.Name); if (ret != Native.Error.AlreadyExists) { if (ret != 0) { throw new Exception("Invalid EntryName format."); } } //get the size for a RASENTRY ret = Native.RasGetEntryProperties(null, string.Empty, null, ref cbEntry, null, ref cbDevCfg); byte[] buffer = new byte[cbEntry]; // get a default set of properties ret = Native.RasGetEntryProperties(null, string.Empty, buffer, ref cbEntry, null, ref cbDevCfg); RasEntry entry = new RasEntry(buffer); entry.CountryCode = newEntry.CountryCode; entry.Name = newEntry.Name; entry.Options = newEntry.Options; entry.DeviceType = newEntry.DeviceType; entry.DeviceName = newEntry.DeviceName; entry.AreaCode = newEntry.AreaCode; entry.PhoneNumber = newEntry.PhoneNumber; entry.IPAddress = newEntry.IPAddress; entry.IPAddressDns = newEntry.IPAddressDns; entry.IPAddressDnsAlt = newEntry.IPAddressDnsAlt; entry.IPAddressWins = newEntry.IPAddressWins; entry.IPAddressWinsAlt = newEntry.IPAddressWinsAlt; ret = Native.RasSetEntryProperties(null, entry.Name, entry.Data, cbEntry, null, 0); if (ret == Native.Error.Success) { if (dialParams != null) { entry.SetDialParams(dialParams); } return newEntry; } else { return null; } }