其中回调函数为 RenderCallback p_func
/// <summary> /// 初始化 /// </summary> /// <param name="p_enterise_id">企业ID</param> /// <param name="p_settings">设备属性</param> /// <param name="p_device_infos">获取到设备信息 JSON</param> /// <param name="p_server_url">预留的server URL地址,目前可设置为"https://evn.xjnetworks.com/" </param> /// <param name="p_func">回调函数接口</param> /// <returns></returns> [DllImport("xjsdk.dll", EntryPoint = "XJSdkInit", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern int XJSdkInit(string p_enterise_id, string p_settings, string p_device_infos, string p_server_url, RenderCallback p_func);
1定义委托类:
/// <summary> /// 设定委托 /// </summary> /// <param name="event_type"></param> /// <param name="p_data"></param> [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void RenderCallback(int event_type, string p_data); public static RenderCallback RemoteMsgCallBack;///实例化 public static void RegistRemoteMsgCallBack(string p_enterise_id, string p_settings, string p_device_infos, string p_server_url, RenderCallback p_func) { XJSdkInit(p_enterise_id, p_settings, p_device_infos, p_server_url, RemoteMsgCallBack); }///重写操作
程序端调用方法:
DllBaseSDK.RemoteMsgCallBack = CallBackFunction; DllBaseSDK.RegistRemoteMsgCallBack(Mmsg.QiyeId, Mmsg.SBName, MsgAll, Url, CallBackFunction);
也可以是这样的:
public RenderCallback globalCallbackProcedure;//全局调用委托 globalCallbackProcedure = new RenderCallback(CallBackFunction);//loading里写 DllBaseSDK.RegistRemoteMsgCallBack(Mmsg.QiyeId, Mmsg.SBName, MsgAll, Url, globalCallbackProcedure );//最后是调用