LoginSignup
3
4

More than 5 years have passed since last update.

C#でネイティブ関数ポインタコール

Posted at

IntPtrで渡された関数ポインタをDelegateに変換。

using System;
using System.Runtime.InteropServices;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int func_i_i(int v);

int CallFunc(IntPtr fp)
{
  func_i_i p;
  p = (func_i_i)Marshal.GetDelegateForFunctionPointer(fp, typeof(func_i_i));
  return p(1);
}
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4