|
// 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/).
//
// Only the Get method (vtable index 4) is used. Other methods are documented as
// vtable placeholders for correct indexing.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.Variant;
namespace Microsoft.Build.Shared.Win32.Wmi;
/// <summary>
/// Represents a single CIM object returned from WMI queries.
/// </summary>
/// <remarks>
/// <see href="https://learn.microsoft.com/windows/win32/api/wbemcli/nn-wbemcli-iwbemclassobject"/>
/// </remarks>
[SupportedOSPlatform("windows6.0")]
internal unsafe struct IWbemClassObject : IComIID
{
public static Guid Guid { get; } = new(0xDC12A681, 0x737F, 0x11CF, 0x88, 0x4D, 0x00, 0xAA, 0x00, 0x4B, 0x2E, 0x24);
static ref readonly Guid IComIID.Guid
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ReadOnlySpan<byte> data =
[
0x81, 0xA6, 0x12, 0xDC,
0x7F, 0x73,
0xCF, 0x11,
0x88, 0x4D, 0x00, 0xAA, 0x00, 0x4B, 0x2E, 0x24
];
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 (IWbemClassObject* pThis = &this)
{
return ((delegate* unmanaged[Stdcall]<IWbemClassObject*, Guid*, void**, HRESULT>)_lpVtbl[0])(pThis, riid, ppvObject);
}
}
public uint AddRef()
{
fixed (IWbemClassObject* pThis = &this)
{
return ((delegate* unmanaged[Stdcall]<IWbemClassObject*, uint>)_lpVtbl[1])(pThis);
}
}
public uint Release()
{
fixed (IWbemClassObject* pThis = &this)
{
return ((delegate* unmanaged[Stdcall]<IWbemClassObject*, uint>)_lpVtbl[2])(pThis);
}
}
// IWbemClassObject vtable layout (indices 3-26):
// 3 = GetQualifierSet
// 4 = Get <-- Used
// 5 = Put
// 6 = Delete
// 7 = GetNames
// 8 = BeginEnumeration
// 9 = Next
// 10 = EndEnumeration
// 11 = GetPropertyQualifierSet
// 12 = Clone
// 13 = GetObjectText
// 14 = SpawnDerivedClass
// 15 = SpawnInstance
// 16 = CompareTo
// 17 = GetPropertyOrigin
// 18 = InheritsFrom
// 19 = GetMethod
// 20 = PutMethod
// 21 = DeleteMethod
// 22 = BeginMethodEnumeration
// 23 = NextMethod
// 24 = EndMethodEnumeration
// 25 = GetMethodQualifierSet
// 26 = GetMethodOrigin
/// <summary>
/// Gets the value of a named property. Returns a VARIANT containing the value.
/// </summary>
/// <remarks>
/// <see href="https://learn.microsoft.com/windows/win32/api/wbemcli/nf-wbemcli-iwbemclassobject-get"/>
/// </remarks>
public HRESULT Get(char* wszName, int lFlags, VARIANT* pVal, int* pType, int* plFlavor)
{
fixed (IWbemClassObject* pThis = &this)
{
return ((delegate* unmanaged[Stdcall]<IWbemClassObject*, char*, int, VARIANT*, int*, int*, HRESULT>)_lpVtbl[4])(
pThis, wszName, lFlags, pVal, pType, plFlavor);
}
}
}
|