diff --git a/PInvoke/NetListMgr/NetListMgr.cs b/PInvoke/NetListMgr/NetListMgr.cs
index 84beea7d..94c292dd 100644
--- a/PInvoke/NetListMgr/NetListMgr.cs
+++ b/PInvoke/NetListMgr/NetListMgr.cs
@@ -183,7 +183,7 @@ namespace Vanara.PInvoke.NetListMgr
/// Returns an enumerator that iterates through a collection.
/// An object that can be used to iterate through the collection.
[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
/// Pointer to a list of pointers returned by INetworkConnection.
/// Pointer to the number of elements supplied. May be NULL if celt is one.
[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);
/// The Skip method skips over the next specified number of elements in the enumeration sequence.
/// Number of elements to skip over in the enumeration.
@@ -222,7 +222,7 @@ namespace Vanara.PInvoke.NetListMgr
/// Returns an enumerator that iterates through a collection.
/// An object that can be used to iterate through the collection.
[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
/// Pointer to a list of pointers returned by INetworkConnection.
/// Pointer to the number of elements supplied. May be NULL if celt is one.
[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);
/// The Skip method skips over the next specified number of elements in the enumeration sequence.
/// Number of elements to skip over in the enumeration.
diff --git a/UnitTests/PInvoke/NetListMgr/NetListMgrTests.cs b/UnitTests/PInvoke/NetListMgr/NetListMgrTests.cs
index ed9d9b51..9f1ad9a7 100644
--- a/UnitTests/PInvoke/NetListMgr/NetListMgrTests.cs
+++ b/UnitTests/PInvoke/NetListMgr/NetListMgrTests.cs
@@ -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]