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.05k stars 85 forks source link

Improve bit fields support #987

Closed Nuklon closed 7 months ago

Nuklon commented 1 year ago

Actual behavior

This for example: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/d3dkmthk/ns-d3dkmthk-_d3dkmt_adaptertype

is generated as:

        [global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.18-beta+dc807e7787")]
        internal partial struct D3DKMT_ADAPTERTYPE
        {
            internal _Anonymous_e__Union Anonymous;

            [StructLayout(LayoutKind.Explicit)]
            [global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.18-beta+dc807e7787")]
            internal partial struct _Anonymous_e__Union
            {
                [FieldOffset(0)]
                internal _Anonymous_e__Struct Anonymous;

                [FieldOffset(0)]
                internal uint Value;

                [global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.18-beta+dc807e7787")]
                internal partial struct _Anonymous_e__Struct
                {
                    internal uint _bitfield;
                }
            }
        }

Expected behavior

Generate helpers around Value for RenderSupported, DisplaySupported, etc.

Repro steps

  1. NativeMethods.txt content:
    D3DKMT_ADAPTERTYPE

Context

AArnott commented 1 year ago

It looks like @mikebattista recently did work in https://github.com/microsoft/win32metadata/pull/1620 to improve this. CsWin32 probably just has to leverage it.

AArnott commented 7 months ago

Reactivating because there is lots to fix.