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
2.07k stars 87 forks source link

`ShellExecuteEx` is not generated #1102

Closed vitkuz573 closed 9 months ago

vitkuz573 commented 9 months ago

Actual behavior

ShellExecuteEx is not generated with the message warning PInvoke005: This API is only available when targeting a specific CPU architecture. AnyCPU cannot generate this API. But at the same time ShellExecute is generated correctly

Is this an error?

Expected behavior

Correct generation of ShellExecuteEx

Repro steps

  1. NativeMethods.txt content:

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

  3. Any of your own code that should be shared?

Context

AArnott commented 9 months ago

This is by design. Per the win32metadata that is the basis for code generation, the ShellExecuteEx function references the SHELLEXECUTEINFOW type, which is declared differently for x86 than for x64 and arm64 architectures. This makes it impossible to emit one C# declaration of the struct that will work on any CPU.

So per the error message, if you change your project to target specific platforms, you'll get what you need.