|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// Manually defined WMI COM struct following CsWin32 struct-based COM patterns.
// WMI interfaces are not in Win32 metadata, so they cannot be generated by CsWin32.
// Pattern follows dotnet/sdk ISetupConfiguration.cs (src/Cli/dotnet/Microsoft/VisualStudio/Setup/Configuration/).
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Windows.Win32;
using Windows.Win32.Foundation;
namespace Microsoft.Build.Shared.Win32.Wmi;
/// <summary>
/// Used to enumerate CIM objects returned by <see cref="IWbemServices.ExecQuery"/>.
/// </summary>
/// <remarks>
/// <see href="https://learn.microsoft.com/windows/win32/api/wbemcli/nn-wbemcli-ienumwbemclassobject"/>
/// </remarks>
[SupportedOSPlatform("windows6.0")]
internal unsafe struct IEnumWbemClassObject : IComIID
{
public static Guid Guid { get; } = new(0x027947E1, 0xD731, 0x11CE, 0xA3, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01);
static ref readonly Guid IComIID.Guid
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ReadOnlySpan<byte> data =
[
0xE1, 0x47, 0x79, 0x02,
0x31, 0xD7,
0xCE, 0x11,
0xA3, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
];
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
}
}
private readonly void** _lpVtbl;
// IUnknown methods (vtable indices 0-2)
public HRESULT QueryInterface(Guid* riid, void** ppvObject)
{
fixed (IEnumWbemClassObject* pThis = &this)
{
return ((delegate* unmanaged[Stdcall]<IEnumWbemClassObject*, Guid*, void**, HRESULT>)_lpVtbl[0])(pThis, riid, ppvObject);
}
}
public uint AddRef()
{
fixed (IEnumWbemClassObject* pThis = &this)
{
return ((delegate* unmanaged[Stdcall]<IEnumWbemClassObject*, uint>)_lpVtbl[1])(pThis);
}
}
public uint Release()
{
fixed (IEnumWbemClassObject* pThis = &this)
{
return ((delegate* unmanaged[Stdcall]<IEnumWbemClassObject*, uint>)_lpVtbl[2])(pThis);
}
}
// IEnumWbemClassObject vtable layout (indices 3-7):
// 3 = Reset
// 4 = Next <-- Used
// 5 = NextAsync
// 6 = Clone
// 7 = Skip
/// <summary>
/// Retrieves the next object(s) in the enumeration, waiting up to a specified timeout.
/// </summary>
/// <remarks>
/// <see href="https://learn.microsoft.com/windows/win32/api/wbemcli/nf-wbemcli-ienumwbemclassobject-next"/>
/// </remarks>
public HRESULT Next(int lTimeout, uint uCount, IWbemClassObject** apObjects, uint* puReturned)
{
fixed (IEnumWbemClassObject* pThis = &this)
{
return ((delegate* unmanaged[Stdcall]<IEnumWbemClassObject*, int, uint, IWbemClassObject**, uint*, HRESULT>)_lpVtbl[4])(
pThis, lTimeout, uCount, apObjects, puReturned);
}
}
}
|