private void open_enum()
            {
                uint res = 0;

                res = WinApiWNET.WNetOpenEnum
                          (inittial_scope,
                          initial_type,
                          initial_usage,
                          ref resource_root,
                          ref enum_handle);

                //check result
                if (res != WinApiWNET.NO_ERROR)
                {
                    if (res == WinApiWNET.ERROR_EXTENDED_ERROR)
                    {
                        WNetException.ThrowOnError();
                    }
                    else
                    {
                        throw new Win32Exception((int)res);
                    }
                }
                //allocate buffer
                buffer = Marshal.AllocHGlobal(buffer_size);
            }
Example #2
0
        private static NETRESOURCE GetResourceInfo(NETRESOURCE resource, int buffer_size)
        {
            var info_buffer = IntPtr.Zero;
            //int buffer_size = 512;
            var system_ptr = IntPtr.Zero;

            try
            {
                info_buffer = Marshal.AllocHGlobal(buffer_size);

                var res = WinApiWNET.WNetGetResourceInformation
                              (ref resource,
                              info_buffer,
                              ref buffer_size,
                              ref system_ptr);
                //check res
                switch (res)
                {
                case WinApiWNET.ERROR_EXTENDED_ERROR:
                    WNetException.ThrowOnError();
                    return(new NETRESOURCE());

                case WinApiWNET.ERROR_MORE_DATA:
                    //alloc new buffer
                    Marshal.FreeHGlobal(info_buffer);
                    return(GetResourceInfo(resource, buffer_size));

                case WinApiWNET.NO_ERROR:
                    var ret = new NETRESOURCE();
                    NETRESOURCE.FromBuffer(info_buffer, 0, ref ret);
                    return(ret);

                default:
                    throw new Win32Exception((int)res);
                }
            }
            finally
            {
                if (info_buffer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(info_buffer);
                }
            }
        }
            private bool continue_enum()
            {
                int req_entries = requested_entries;

                uint res = WinApiWNET.WNetEnumResource
                               (enum_handle,
                               ref req_entries,
                               buffer,
                               ref buffer_size);

                //check result
                switch (res)
                {
                case WinApiWNET.NO_ERROR:
                    //success
                    current_entries_in_buffer        = req_entries;
                    current_entries_in_buffer_readed = 0;
                    return(true);

                case WinApiWNET.ERROR_NO_MORE_ITEMS:
                    //enumerate comletes
                    current_entries_in_buffer        = 0;
                    current_entries_in_buffer_readed = 0;
                    return(false);

                case WinApiWNET.ERROR_MORE_DATA:
                    //buffer small?
                    //allocate new buffer
                    Marshal.FreeHGlobal(buffer);
                    buffer = Marshal.AllocHGlobal(buffer_size);
                    //and recall
                    return(continue_enum());

                case WinApiWNET.ERROR_EXTENDED_ERROR:
                    WNetException.ThrowOnError();
                    return(false);

                default:
                    throw new Win32Exception((int)res);
                    //return false;
                }
            }
Example #4
0
        public static NETRESOURCE GetParentResource(NETRESOURCE resource)
        {
            var buffer      = IntPtr.Zero;
            var buffer_size = 256;
            var ret         = new NETRESOURCE();

            try
            {
                buffer = Marshal.AllocHGlobal(buffer_size);
                var res = WinApiWNET.WNetGetResourceParent
                              (ref resource,
                              buffer,
                              ref buffer_size);
                if (res == WinApiWNET.ERROR_MORE_DATA)
                {
                    res = WinApiWNET.WNetGetResourceParent
                              (ref resource,
                              buffer,
                              ref buffer_size);
                }
                if (res == WinApiWNET.ERROR_EXTENDED_ERROR)
                {
                    WNetException.ThrowOnError();
                }
                if (res != WinApiWNET.NO_ERROR)
                {
                    throw new Win32Exception((int)res);
                }
                NETRESOURCE.FromBuffer(buffer, 0, ref ret);
                return(ret);
            }
            finally
            {
                if (buffer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(buffer);
                }
            }
        }