dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.81k stars 196 forks source link

Add missing HRESULT constant #490

Open tajbender opened 1 month ago

tajbender commented 1 month ago

Is your feature request related to a problem? Please describe.

I found a COM HResult error constant, that isn't present in Vanara

Describe the additions or enhancements you'd like

I've found HResult 0x80070490 which I use in an Application that deals with Shell32 objects using Vanara. The code is used in Vanara itself, as found here:

    /// <summary>Retrieves a data stream corresponding to this theme, starting from a specified part and state.</summary>
    /// <param name="hInst">The SafeLibraryHandle of a loaded styles file.</param>
    /// <param name="partId">Specifies the part to retrieve a stream from.</param>
    /// <param name="stateId">Specifies the state of the part.</param>
    /// <returns>The data stream.</returns>
    public byte[]? GetDiskStream(HINSTANCE hInst, int partId, int stateId)
    {
        var r = GetThemeStream(Handle, partId, stateId, (int)ThemeProperty.TMT_DISKSTREAM, out var bytes, out var bLen, hInst);
        if (r.Succeeded) return bytes.ToByteArray((int)bLen);
        if (r != 0x80070490) throw new InvalidOperationException("Bad GetThemeStream");
        return null;
    }

and here:

    /// <summary>Retrieves a data stream corresponding to this theme, starting from a specified part and state.</summary>
    /// <param name="partId">Specifies the part to retrieve a stream from.</param>
    /// <param name="stateId">Specifies the state of the part.</param>
    /// <returns>The data stream.</returns>
    public byte[]? GetStream(int partId, int stateId)
    {
        var r = GetThemeStream(Handle, partId, stateId, (int)ThemeProperty.TMT_STREAM, out var bytes, out var bLen, HINSTANCE.NULL);
        if (r.Succeeded) return bytes.ToByteArray((int)bLen);
        if (r != 0x80070490) throw new InvalidOperationException("Bad GetThemeStream");
        return null;
    }

Previous work

I've found this HResult by Try & Error. It is fired when, as far as I remember, someone tries to enumerate an empty disk drive.

I've called it HResult_ElementNotFound, but I don't know if this is official naming.

Your thoughts on this?

tajbender commented 1 month ago

You may https://searchcode.com/?q=0x80070490 give a try.

I've found some naming, e.g. in WIX: https://searchcode.com/file/28621585/src/ext/BalExtension/mba/core/NativeMethods.cs/

internal const int E_NOTFOUND = unchecked((int)0x80070490);

Regards, tajbender