microsoft / win32metadata

Tooling to generate metadata for Win32 APIs in the Windows SDK.
Other
1.32k stars 113 forks source link

Not all types are from authif.h are generated as expected #1851

Open iSazonov opened 7 months ago

iSazonov commented 7 months ago

Actual behavior

I found that not all types are from authif.h are generated as expected.

Expected behavior

Metadata for RADIUS_ATTRIBUTE_ARRAY:

[Documentation("https://learn.microsoft.com/windows/win32/api/authif/ns-authif-radius_attribute_array")]
[StructSizeField("cbSize")]
public struct RADIUS_ATTRIBUTE_ARRAY
{
    public uint cbSize;
    public IntPtr Add;
    [Const]
    public IntPtr AttributeAt;
    public IntPtr GetSize;
    public IntPtr InsertAt;
    public IntPtr RemoveAt;
    public IntPtr SetAt;
}

Generated code:

    internal partial struct RADIUS_ATTRIBUTE_ARRAY
    {
        internal uint cbSize;
        internal nint Add;
        internal nint AttributeAt;
        internal nint GetSize;
        internal nint InsertAt;
        internal nint RemoveAt;
        internal nint SetAt;
        }

Expected code:

        internal unsafe partial struct RADIUS_ATTRIBUTE_ARRAY
        {
            internal uint cbSize;
            internal delegate* <RADIUS_ATTRIBUTE_ARRAY*, RADIUS_ATTRIBUTE*> Add;
            internal delegate* <RADIUS_ATTRIBUTE_ARRAY*, uint, RADIUS_ATTRIBUTE*> AttributeAt;
            internal delegate* <RADIUS_ATTRIBUTE_ARRAY*, uint> GetSize;
            internal delegate* <RADIUS_ATTRIBUTE_ARRAY*, uint, RADIUS_ATTRIBUTE*, uint> InsertAt;
            internal delegate* <RADIUS_ATTRIBUTE_ARRAY*, uint> RemoveAt;
            internal delegate* <RADIUS_ATTRIBUTE_ARRAY*, uint, RADIUS_ATTRIBUTE*, uint> SetAt;
        }

The same for RADIUS_EXTENSION_CONTROL_BLOCK (GetRequest, GetResponse, SetResponseType). Expected code:

            internal delegate* unmanaged <RADIUS_EXTENSION_CONTROL_BLOCK*, RADIUS_ATTRIBUTE_ARRAY*> GetRequest;
            internal delegate* unmanaged <RADIUS_EXTENSION_CONTROL_BLOCK*, RADIUS_CODE, RADIUS_ATTRIBUTE_ARRAY*> GetResponse;
            internal delegate* unmanaged <RADIUS_EXTENSION_CONTROL_BLOCK*, RADIUS_CODE, uint> SetResponseType;

Also I would expect to be generated entry points for callbacks (now there are only delegate types corresponding to them): (although this may not be what this project is for, it could nevertheless be commented out code as a sample.)

    [UnmanagedCallersOnly(EntryPoint = "RadiusExtensionProcess2")]
    public unsafe static uint RadiusExtensionProcess2(IntPtr arg)
    {
    }

    [UnmanagedCallersOnly(EntryPoint = "RadiusExtensionInit")]
    public static uint RadiusExtensionInit()
    {
    }

    [UnmanagedCallersOnly(EntryPoint = "RadiusExtensionTerm")]
    public static void RadiusExtensionTerm()
    {
    }

Repro steps

  1. NativeMethods.txt content:

    Windows.Win32.NetworkManagement.NetworkPolicyServer.PRADIUS_EXTENSION_PROCESS
    RADIUS_*
    PRADIUS_EXTENSION_PROCESS_2
  2. NativeMethods.json content (if present):



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

### Context

- CsWin32 version: 0.3.49-beta
- Win32Metadata version (if explicitly set by project): 58.0.18-preview
- Target Framework: net8.0
- `LangVersion` (if explicitly set by project): [e.g. `9`]
AArnott commented 6 months ago

There is no way CsWin32 can generate function pointers when the metadata only gives us IntPtr. I'll move this to the metadata repo so they can correct it there.

mikebattista commented 6 months ago

These delegates need to be manually defined similar to https://github.com/microsoft/win32metadata/issues/842.