/// <summary> /// Retrieves the value of an AutoDial parameter. /// </summary> /// <param name="parameter">The parameter whose value to retrieve.</param> /// <returns>The value of the parameter.</returns> public int GetAutoDialParameter(NativeMethods.RASADP parameter) { int retval = 0; RasGetAutodialParamParams info = new RasGetAutodialParamParams(); info.BufferSize = sizeof(int); bool retry = false; do { try { info.Address = Marshal.AllocHGlobal(info.BufferSize); int ret = UnsafeNativeMethods.Instance.GetAutodialParam(info); if (ret == NativeMethods.SUCCESS) { if (info.BufferSize == sizeof(int)) { retval = Marshal.ReadInt32(info.Address); } else { ThrowHelper.ThrowInvalidOperationException(Resources.Exception_UnexpectedSizeReturned); } retry = false; } else if (ret == NativeMethods.ERROR_BUFFER_TOO_SMALL) { retry = true; } else { ThrowHelper.ThrowRasException(ret); } } catch (EntryPointNotFoundException) { ThrowHelper.ThrowNotSupportedException(Resources.Exception_NotSupportedOnPlatform); } finally { if (info.Address != IntPtr.Zero) { Marshal.FreeHGlobal(info.Address); } } } while (retry); return retval; }
/// <summary> /// Retrieves the value of an AutoDial parameter. /// </summary> /// <param name="value">An <see cref="RasGetAutodialParamParams"/> containing call data.</param> /// <returns>If the function succeeds, the return value is zero.</returns> public int GetAutodialParam(RasGetAutodialParamParams value) { if (value == null) { ThrowHelper.ThrowArgumentNullException("value"); } int bufferSize = value.BufferSize; PInvokeCallTraceEvent evt = new PInvokeCallTraceEvent(NativeMethods.RasApi32Dll, "RasGetAutodialParam"); evt.Data.Add("key", value.Key); evt.Data.Add("address", value.Address); evt.Data.Add("bufferSize-IN", bufferSize); int result = 0; try { result = UnsafeNativeMethods.RasGetAutodialParam(value.Key, value.Address, ref bufferSize); evt.ResultCode = result; evt.Data.Add("bufferSize-OUT", bufferSize); value.BufferSize = bufferSize; } finally { DiagnosticTrace.Default.TraceEvent(TraceEventType.Verbose, evt); } return result; }
/// <summary> /// Retrieves the value of an AutoDial parameter. /// </summary> /// <param name="value">An <see cref="RasGetAutodialParamParams"/> containing call data.</param> /// <returns>If the function succeeds, the return value is zero.</returns> public int GetAutodialParam(RasGetAutodialParamParams value) { int bufferSize = value.BufferSize; int ret = UnsafeNativeMethods.RasGetAutodialParam(value.Key, value.Address, ref bufferSize); value.BufferSize = bufferSize; return ret; }