Changed compiler option on IEnumNextworkXX interfaces and array parameter on Next methods along with unit test.

pull/161/head
dahall 2020-07-12 14:10:58 -06:00
parent f510b2d32e
commit d124115570
2 changed files with 20 additions and 14 deletions

View File

@ -183,7 +183,7 @@ namespace Vanara.PInvoke.NetListMgr
/// <summary>Returns an enumerator that iterates through a collection.</summary>
/// <returns>An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.</returns>
[DispId(-4)]
#if (NET20 || NET35 || NET40 || NET45)
#if NETFRAMEWORK
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "", MarshalTypeRef = typeof(System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler), MarshalCookie = "")]
new IEnumerator GetEnumerator();
#else
@ -195,7 +195,7 @@ namespace Vanara.PInvoke.NetListMgr
/// <param name="rgelt">Pointer to a list of pointers returned by INetworkConnection.</param>
/// <param name="pceltFetched">Pointer to the number of elements supplied. May be NULL if celt is one.</param>
[DispId(1), PreserveSig]
HRESULT Next(uint celt, [MarshalAs(UnmanagedType.Interface)] out INetworkConnection rgelt, out uint pceltFetched);
HRESULT Next(uint celt, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 0)] INetworkConnection[] rgelt, out uint pceltFetched);
/// <summary>The Skip method skips over the next specified number of elements in the enumeration sequence.</summary>
/// <param name="celt">Number of elements to skip over in the enumeration.</param>
@ -222,7 +222,7 @@ namespace Vanara.PInvoke.NetListMgr
/// <summary>Returns an enumerator that iterates through a collection.</summary>
/// <returns>An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.</returns>
[DispId(-4)]
#if (NET20 || NET35 || NET40 || NET45)
#if NETFRAMEWORK
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "", MarshalTypeRef = typeof(System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler), MarshalCookie = "")]
new IEnumerator GetEnumerator();
#else
@ -234,7 +234,7 @@ namespace Vanara.PInvoke.NetListMgr
/// <param name="rgelt">Pointer to a list of pointers returned by INetworkConnection.</param>
/// <param name="pceltFetched">Pointer to the number of elements supplied. May be NULL if celt is one.</param>
[DispId(1), PreserveSig]
HRESULT Next(uint celt, [MarshalAs(UnmanagedType.Interface)] out INetwork rgelt, out uint pceltFetched);
HRESULT Next(uint celt, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 0)] INetwork[] rgelt, out uint pceltFetched);
/// <summary>The Skip method skips over the next specified number of elements in the enumeration sequence.</summary>
/// <param name="celt">Number of elements to skip over in the enumeration.</param>

View File

@ -4,6 +4,8 @@ using System.Linq;
using Vanara.Extensions;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
using Vanara.PInvoke.NetListMgr;
using Vanara.InteropServices;
using System.Runtime.InteropServices;
//using NETWORKLIST;
@ -37,11 +39,13 @@ namespace Vanara.PInvoke.Tests
[Test]
public void GetNetworksTest1()
{
var ns = mgr.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED);
Assert.That(ns, Is.Not.Null);
ns.Next(1, out INetwork connections, out uint fetched);
Assert.That(fetched, Is.EqualTo(1));
Assert.That(connections, Is.Not.Null);
using var ns = ComReleaserFactory.Create(mgr.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED));
Assert.That(ns.Item, Is.Not.Null);
var connections = new INetwork[5];
ns.Item.Next((uint)connections.Length, connections, out uint fetched);
Assert.That(fetched, Is.LessThanOrEqualTo(connections.Length));
for (int i = 0; i < fetched; i++)
Marshal.ReleaseComObject(connections[i]);
}
[Test]
@ -56,11 +60,13 @@ namespace Vanara.PInvoke.Tests
[Test]
public void GetNetworkConnectionsTest1()
{
var ns = mgr.GetNetworkConnections();
Assert.That(ns, Is.Not.Null);
ns.Next(1, out INetworkConnection connections, out uint fetched);
Assert.That(fetched, Is.EqualTo(1));
Assert.That(connections, Is.Not.Null);
var ns = ComReleaserFactory.Create(mgr.GetNetworkConnections());
Assert.That(ns.Item, Is.Not.Null);
var connections = new INetworkConnection[5];
ns.Item.Next((uint)connections.Length, connections, out uint fetched);
Assert.That(fetched, Is.LessThanOrEqualTo(connections.Length));
for (int i = 0; i < fetched; i++)
Marshal.ReleaseComObject(connections[i]);
}
[Test]