https://bugs.winehq.org/show_bug.cgi?id=54226
Bug ID: 54226 Summary: widl: implement `cstruct_out` option to generate C bindings compatible with small struct return values Product: Wine Version: unspecified Hardware: x86-64 OS: Windows Status: UNCONFIRMED Severity: normal Priority: P2 Component: tools Assignee: wine-bugs@winehq.org Reporter: alvin@alvinhc.com
According to https://devblogs.microsoft.com/oldnewthing/20220113-00/?p=106152, the previous C bindings are incompatible with the C++ COM ABI when the method returns a small struct for MSVC. Their solution is to add the `/cstruct_out` flag to the MIDL compiler (https://learn.microsoft.com/en-us/windows/win32/midl/-cstruct-out, added in the Win11 SDK according to comments) to generate new C bindings compatible with the C++ COM ABI.
This is similar to the (long-standing) GCC issue with its mingw-w64 MS ABI (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64384), which has been worked around in widl/mingw-w64 by having special wrapper functions in the C++ bindings, guarded by `WIDL_EXPLICIT_AGGREGATE_RETURNS`.
I think widl should follow suit to implement a `--cstruct_out` flag to do the same thing for the C bindings. This does not need to be guarded by `WIDL_EXPLICIT_AGGREGATE_RETURNS` because both GCC and MSVC has the same issue and will require the same fix. (I do not know if we need some kind of guard for the mingw-w64 headers to revert to the old function declarations, but given that the old bindings are practically broken perhaps it doesn't matter.)
(I have not checked what `/cstruct_out` on MIDL actually does to the C bindings.)