pure CのDLLから呼び出し元C#へのコールバック
///pure C DLL #include "windows.h" #define DLLEXPORT __declspec(dllexport) extern "C" { DLLEXPORT int __stdcall MyFunc(int (*callback)()) { return callback(); } } ///C# class DLL { [DllImport"hoge.dll", CallingConvention = CallingConvention.StdCall)] public static extern int MyFunc(callback cb); public delegate int callback(); public static void main() { callback cb = new callback(callbackfunc); int i = MyFunc(cb); } public static int callbackfunc() { return 10; } } こんな感じでiには10が返る. main(C#)->MyFunc(DLL)->callbackfunc(C#)->MyFunc(DLL)->main(C#) な感じ.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
追記
参考になりそうなサイト発見
http://sgry.sakura.ne.jp/pgarticles/cs_pinvoke_callback.html