Provides information for the RasGetAutodialAddress API call.
Наследование: DotRas.Internal.StructBufferedPInvokeParams
Пример #1
0
        /// <summary>
        /// Retrieves information about the entries associated with a network address in the AutoDial mapping database.
        /// </summary>
        /// <param name="address">The address to retrieve.</param>
        /// <returns>A new <see cref="DotRas.RasAutoDialAddress"/> object.</returns>
        public RasAutoDialAddress GetAutoDialAddress(string address)
        {
            RasAutoDialAddress retval = null;

            int size = Marshal.SizeOf(typeof(NativeMethods.RASAUTODIALENTRY));

            RasGetAutodialAddressParams info = new RasGetAutodialAddressParams();
            info.BufferSize = new IntPtr(size);
            info.Count = IntPtr.Zero;

            bool retry = false;

            do
            {
                NativeMethods.RASAUTODIALENTRY entry = new NativeMethods.RASAUTODIALENTRY();
                entry.size = size;

                try
                {
                    info.Address = Marshal.AllocHGlobal(info.BufferSize);
                    Marshal.StructureToPtr(entry, info.Address, true);

                    int ret = UnsafeNativeMethods.Instance.GetAutodialAddress(info);
                    if (ret == NativeMethods.ERROR_BUFFER_TOO_SMALL)
                    {
                        retry = true;
                    }
                    else if (ret == NativeMethods.SUCCESS)
                    {
                        retry = false;

                        NativeMethods.RASAUTODIALENTRY[] entries = Utilities.CreateArrayOfType<NativeMethods.RASAUTODIALENTRY>(info.Address, size, info.Count.ToInt32());
                        retval = new RasAutoDialAddress(address);

                        if (entries != null || entries.Length > 0)
                        {
                            for (int index = 0; index < entries.Length; index++)
                            {
                                NativeMethods.RASAUTODIALENTRY current = entries[index];
                                retval.Entries.Add(new RasAutoDialEntry(current.dialingLocation, current.entryName));
                            }
                        }
                    }
                    else if (ret == NativeMethods.ERROR_FILE_NOT_FOUND)
                    {
                        retry = false;
                    }
                    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;
        }
Пример #2
0
        /// <summary>
        /// Retrieves information about the entries associated with a network address in the AutoDial mapping database.
        /// </summary>
        /// <param name="value">An <see cref="RasGetAutodialAddressParams"/> containing call data.</param>
        /// <returns>If the function succeeds, the return value is zero.</returns>
        public int GetAutodialAddress(RasGetAutodialAddressParams value)
        {
            if (value == null)
            {
                ThrowHelper.ThrowArgumentNullException("value");
            }

            IntPtr bufferSize = value.BufferSize;
            IntPtr count = value.Count;

            PInvokeCallTraceEvent evt = new PInvokeCallTraceEvent(NativeMethods.RasApi32Dll, "RasGetAutodialAddress");
            evt.Data.Add("autodialAddress", value.AutodialAddress);
            evt.Data.Add("reserved", value.Reserved);
            evt.Data.Add("address", value.Address);
            evt.Data.Add("bufferSize-IN", bufferSize);
            evt.Data.Add("count-IN", count);

            int result = 0;

            try
            {
                result = UnsafeNativeMethods.RasGetAutodialAddress(value.AutodialAddress, value.Reserved, value.Address, ref bufferSize, ref count);
                evt.ResultCode = result;
                evt.Data.Add("bufferSize-OUT", bufferSize);
                evt.Data.Add("count-OUT", count);

                value.BufferSize = bufferSize;
                value.Count = count;
            }
            finally
            {
                DiagnosticTrace.Default.TraceEvent(TraceEventType.Verbose, evt);
            }

            return result;
        }
Пример #3
0
        /// <summary>
        /// Retrieves information about the entries associated with a network address in the AutoDial mapping database.
        /// </summary>
        /// <param name="value">An <see cref="RasGetAutodialAddressParams"/> containing call data.</param>
        /// <returns>If the function succeeds, the return value is zero.</returns>
        public int GetAutodialAddress(RasGetAutodialAddressParams value)
        {
            IntPtr bufferSize = value.BufferSize;
            IntPtr count = value.Count;

            int ret = UnsafeNativeMethods.RasGetAutodialAddress(value.AutodialAddress, value.Reserved, value.Address, ref bufferSize, ref count);
            value.BufferSize = bufferSize;
            value.Count = count;

            return ret;
        }