microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`ShellExecuteEx` is not generated

vitkuz573 opened this issue · comments

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
  1. NativeMethods.json content (if present):
  1. Any of your own code that should be shared?

Context

  • CsWin32 version: [e.g. 0.4.422-beta] 0.3.51-beta
  • Win32Metadata version (if explicitly set by project): 56.0.13-preview
  • Target Framework: [e.g. netstandard2.0] net8.0
  • LangVersion (if explicitly set by project): [e.g. 9] latest

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.