当前位置:网站首页>C # uses monopinvokecallback to directly call back C # function
C # uses monopinvokecallback to directly call back C # function
2022-06-30 05:10:00 【Shannan HSY】
iOS Code :Test.mm
char* TestMakeCString(NSString *str) { const char* string = [str UTF8String]; if (string == NULL) { return NULL; } char* res = (char*)malloc(strlen(string) + 1); strcpy(res, string); return res; } extern "C"{ typedef void (*TestCallback)(const char*eventName); TestCallback _myCallback; void _TestInit(TestCallback callback){ _myCallback=callback; } } @implementation Test -(void) test{ _myCallback(TestMakeCString(@"complete")); } @end
C# Code :test.csusing System.Runtime.InteropServices; public class Test{ public delegate void EventHandler(string eventName, string msg); public event EventHandler callbackHandler; internal delegate void TestCallBack(string eventName); [DllImport("__Internal")] private static extern void _TestInit(TestCallBack callback); [MonoPInvokeCallback(typeof(TestCallBack))] public static void onCallBack(string eventName){ if(eventName=="complete"){ //do something if(callbackHandler!=null)callbackHandler(eventName,"HIJK"); } } public static Test _instance; public static Test getInstance(){ if(_instance==null){ _instance=new Test(); } return _instance; } // Initial interface public void init(){ _TestInit(onCallBack); } }
test demo:Test test=Test.getInstance() test.init(); test.callbackHandler+=handler; void handler(string eventName,string msg){ //do something }
边栏推荐
- mmcv常用API介绍
- 2021-03-16
- Force buckle 704 Binary search
- Unity project hosting platform plasticscm (learn to use 2)
- Unity profiler performance analysis
- ParticleSystem in the official Manual of unity_ Collision module
- QT connecting external libraries
- 003-JS-DOM-Attr-innerText
- Operation file file class method
- [note] usage model tree of the unity resource tree structure virtualizingtreeview
猜你喜欢

Records of problems encountered in unity + hololens development

Ugui uses its own function to realize reverse mask

Pycharm database tool
![[notes] unity webgl input Chinese](/img/f7/805f510ff691227b4c2b529cc1099a.jpg)
[notes] unity webgl input Chinese

Oracle-数据的基本操作

Records of some problems encountered during unity development (continuously updated)

Procedural animation -- inverse kinematics of tentacles

Intellj idea generates jar packages for projects containing external lib to other projects. The method refers to the jar package written by itself

Create transfer generation point

Deeply understand the function calling process of C language
随机推荐
Unity project hosting platform plasticscm (learn to use 1)
力扣209. 长度最小的子数组
svg和canvas的区别
2021-06-17 solve the problem of QML borderless window stretching, window jitter and flicker when stretching and shrinking
Procedural animation -- inverse kinematics of tentacles
[notes] unity Scrollview button page turning
Unity publishing /build settings
炒美原油的国际交易平台如何能保障资金安全呢?
【VCS+Verdi联合仿真】~ 以计数器为例
JPA复合主键使用
Four methods of unity ugui button binding events
Unity automatic pathfinding
ParticleSystem in the official Manual of unity_ Collision module
力扣704. 二分查找
Unity supports the platform # define instruction of script
Unity multiple UI page turning left and right
Force buckle 704 Binary search
Revit二次开发---未打开项目使用面板功能
MinGW-w64下载文件失败the file has been downloaded incorrectly!
LXC 和 LXD 容器总结