当前位置:网站首页>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 }
边栏推荐
- 东塔攻防世界—xss绕过安全狗
- Postman 做测试的 6 个常见问题
- mmdet之Loss模块详解
- Unity lens making
- Revit二次开发---未打开项目使用面板功能
- pytorch中常用损失函数总结
- pycharm 数据库工具
- Unity ugui text value suspended enlarged display add text background
- Chapter 10 of OpenGL super classic (7th Edition) calculation shader
- Tcp/ip protocol details Volume I (Reading Guide)
猜你喜欢

pycharm 数据库工具

Unity is associated with vs. there is a compiler problem when opening

Connect() and disconnect() of socket in C #

The file has been downloaded incorrectly!

mmcv常用API介绍

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

Unreal 4 unavigationsystemv1 compilation error

Procedural animation -- inverse kinematics of tentacles

Detailed explanation of the process of "flyingbird" small game (camera adjustment and following part)

Force buckle 27 Removing Elements
随机推荐
Generate a slice of mesh Foundation
Steamvr causes abnormal scene camera
Unity call Exe program
Ripple effect of mouse click (unity & shader)
Unity Logitech steering wheel access
Connect() and disconnect() of socket in C #
Unity ugui text value suspended enlarged display add text background
Nestjs配置静态资源,模板引擎以及Post示例
ParticleSystem in the official Manual of unity_ Collision module
Pycharm database tool
Unity3d learning notes-1 (C # learning)
Go Land no tests were Run: FMT cannot be used. Printf () & lt; BUG & gt;
Does the tester need to analyze the cause of the bug?
Oracle-数据的基本操作
Unity automatic pathfinding
Unity scroll view element drag and drop to automatically adsorb centering and card effect
Tcp/ip protocol details Volume I (Reading Guide)
【VCS+Verdi联合仿真】~ 以计数器为例
Nestjs configures static resources, template engine, and post examples
2021-06-17 solve the problem of QML borderless window stretching, window jitter and flicker when stretching and shrinking