Skip to content

Add CreateDelegatePointer for PROC and FARPROC #1638

@wherewhere

Description

@wherewhere

Is your feature request related to a problem? Please describe.

For now, we have CreateDelegate to create delegate from PROC and FARPROC. But when the delegate has generated to a struct for delegate*, it cannot work.

Describe the solution you'd like

Add a CreateDelegatePointer method for PROC and FARPROC, such as:

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal TDelegate CreateDelegatePointer<TDelegate>() where T : unmanaged => Unsafe.As<PROC, T>(ref this.Value);

Describe alternatives you've considered

For now, we can create an extension to use it:

JClass mainClass = env->functions->FindClass.CreateDelegatePointer<FindClass>().Value(env, "java/lang/String"u8.AsPCSTR());

file static class Extensions
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static PCSTR AsPCSTR(this scoped in ReadOnlySpan<byte> data) => Unsafe.As<ReadOnlySpan<byte>, PCSTR>(ref Unsafe.AsRef(in data));

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static TDelegate CreateDelegatePointer<TDelegate>(this PROC function) where T : unmanaged => Unsafe.As<PROC, T>(ref function);
}

Additional context
#1629

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions