Skip to content

Get MethodInfo from managed function pointer? #46215

Answered by PathogenDavid
acaly asked this question in Q&A
Discussion options

You must be logged in to vote

If you don't strictly need a MethodInfo, but rather just information about the method the function pointer refers to, you can use ClrMD for this.

For example:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Diagnostics.Runtime;
using System.Linq;

public static unsafe class Program
{
    public static void Main(string[] args)
    {
        IntPtr user32 = NativeLibrary.Load("User32.dll");

        delegate*<void> managed1 = &TestMethod;
        delegate*<void> managed2 = &AnotherMethod;
        delegate*<void> managed3 = &MessageBoxW;
        delegate* unmanaged<void> unmanaged1 = &UnmanagedMethod;
        delegate* unmanaged<void> unmanaged2 = (

Replies: 1 comment 19 replies

Comment options

You must be logged in to vote
19 replies
@acaly
Comment options

@GrabYourPitchforks
Comment options

@acaly
Comment options

@GrabYourPitchforks
Comment options

@acaly
Comment options

Answer selected by acaly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants