mirror of https://github.com/dahall/Vanara.git
Changed compiler option on IEnumNextworkXX interfaces and array parameter on Next methods along with unit test.
parent
f510b2d32e
commit
d124115570
|
@ -183,7 +183,7 @@ namespace Vanara.PInvoke.NetListMgr
|
||||||
/// <summary>Returns an enumerator that iterates through a collection.</summary>
|
/// <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>
|
/// <returns>An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.</returns>
|
||||||
[DispId(-4)]
|
[DispId(-4)]
|
||||||
#if (NET20 || NET35 || NET40 || NET45)
|
#if NETFRAMEWORK
|
||||||
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "", MarshalTypeRef = typeof(System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler), MarshalCookie = "")]
|
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "", MarshalTypeRef = typeof(System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler), MarshalCookie = "")]
|
||||||
new IEnumerator GetEnumerator();
|
new IEnumerator GetEnumerator();
|
||||||
#else
|
#else
|
||||||
|
@ -195,7 +195,7 @@ namespace Vanara.PInvoke.NetListMgr
|
||||||
/// <param name="rgelt">Pointer to a list of pointers returned by INetworkConnection.</param>
|
/// <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>
|
/// <param name="pceltFetched">Pointer to the number of elements supplied. May be NULL if celt is one.</param>
|
||||||
[DispId(1), PreserveSig]
|
[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>
|
/// <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>
|
/// <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>
|
/// <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>
|
/// <returns>An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.</returns>
|
||||||
[DispId(-4)]
|
[DispId(-4)]
|
||||||
#if (NET20 || NET35 || NET40 || NET45)
|
#if NETFRAMEWORK
|
||||||
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "", MarshalTypeRef = typeof(System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler), MarshalCookie = "")]
|
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "", MarshalTypeRef = typeof(System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler), MarshalCookie = "")]
|
||||||
new IEnumerator GetEnumerator();
|
new IEnumerator GetEnumerator();
|
||||||
#else
|
#else
|
||||||
|
@ -234,7 +234,7 @@ namespace Vanara.PInvoke.NetListMgr
|
||||||
/// <param name="rgelt">Pointer to a list of pointers returned by INetworkConnection.</param>
|
/// <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>
|
/// <param name="pceltFetched">Pointer to the number of elements supplied. May be NULL if celt is one.</param>
|
||||||
[DispId(1), PreserveSig]
|
[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>
|
/// <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>
|
/// <param name="celt">Number of elements to skip over in the enumeration.</param>
|
||||||
|
|
|
@ -4,6 +4,8 @@ using System.Linq;
|
||||||
using Vanara.Extensions;
|
using Vanara.Extensions;
|
||||||
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
|
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
|
||||||
using Vanara.PInvoke.NetListMgr;
|
using Vanara.PInvoke.NetListMgr;
|
||||||
|
using Vanara.InteropServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
//using NETWORKLIST;
|
//using NETWORKLIST;
|
||||||
|
|
||||||
|
@ -37,11 +39,13 @@ namespace Vanara.PInvoke.Tests
|
||||||
[Test]
|
[Test]
|
||||||
public void GetNetworksTest1()
|
public void GetNetworksTest1()
|
||||||
{
|
{
|
||||||
var ns = mgr.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED);
|
using var ns = ComReleaserFactory.Create(mgr.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED));
|
||||||
Assert.That(ns, Is.Not.Null);
|
Assert.That(ns.Item, Is.Not.Null);
|
||||||
ns.Next(1, out INetwork connections, out uint fetched);
|
var connections = new INetwork[5];
|
||||||
Assert.That(fetched, Is.EqualTo(1));
|
ns.Item.Next((uint)connections.Length, connections, out uint fetched);
|
||||||
Assert.That(connections, Is.Not.Null);
|
Assert.That(fetched, Is.LessThanOrEqualTo(connections.Length));
|
||||||
|
for (int i = 0; i < fetched; i++)
|
||||||
|
Marshal.ReleaseComObject(connections[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -56,11 +60,13 @@ namespace Vanara.PInvoke.Tests
|
||||||
[Test]
|
[Test]
|
||||||
public void GetNetworkConnectionsTest1()
|
public void GetNetworkConnectionsTest1()
|
||||||
{
|
{
|
||||||
var ns = mgr.GetNetworkConnections();
|
var ns = ComReleaserFactory.Create(mgr.GetNetworkConnections());
|
||||||
Assert.That(ns, Is.Not.Null);
|
Assert.That(ns.Item, Is.Not.Null);
|
||||||
ns.Next(1, out INetworkConnection connections, out uint fetched);
|
var connections = new INetworkConnection[5];
|
||||||
Assert.That(fetched, Is.EqualTo(1));
|
ns.Item.Next((uint)connections.Length, connections, out uint fetched);
|
||||||
Assert.That(connections, Is.Not.Null);
|
Assert.That(fetched, Is.LessThanOrEqualTo(connections.Length));
|
||||||
|
for (int i = 0; i < fetched; i++)
|
||||||
|
Marshal.ReleaseComObject(connections[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
Loading…
Reference in New Issue