Skip to content

How to get the function pointer of a static function? #8066

Closed Answered by hez2010
ChinaChenMingQuan asked this question in General
Discussion options

You must be logged in to vote

Use UnmanagedCallerOnly to indicate your function will only be called from unmanaged code:

using System.Runtime.InteropServices;

class TestClass
{
    public unsafe delegate* unmanaged<int> GetHandler()
    {
        return (delegate* unmanaged<int>)&CSharpFunc;
    }
    
    [UnmanagedCallersOnly]
    static int CSharpFunc()
    {
        return default;
    }
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ChinaChenMingQuan
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants