microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
1.99k stars 84 forks source link

IShellItemImageFactory.GetImage should return HRESULT #1189

Closed myth384 closed 4 weeks ago

myth384 commented 1 month ago

Actual behavior

Currently IShellItemImageFactory.GetImage returns void.

Expected behavior

According to the official documentation it should return an HRESULT.

Repro steps

  1. NativeMethods.txt content:

    IShellItemImageFactory
  2. NativeMethods.json content (if present):

    {
    "$schema": "https://aka.ms/CsWin32.schema.json"
    }
  3. Any of your own code that should be shared?

Context

AArnott commented 4 weeks ago

CsWin32 is doing the default .NET thing: considering PreserveSig to be false by default. If a failing HRESULT were to be returned from this API, an exception would be thrown to your code. Or if you are the one implementing the interface, you should throw an exception to produce a failing HRESULT for your native caller.

If you really want an HRESULT instead of exceptions, you can add this API to the list of preservesig APIs as described in the readme.