转载地址:http://www.cnblogs.com/dipwater/archive/2012/11/07/dipwater_delegate.html
同类可参考:
http://www.cnblogs.com/cssmystyle/archive/2012/03/15/2397524.html
1. 定义回调函数对应的委托
1 [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall, CharSet = CharSet.Ansi)] 2 public delegate void RealCallback(int hRealHandle, int dwDataType, IntPtr buffer, uint dwSize, IntPtr lpVoid);
2. 参数定义为 Delegate
1 [DllImport(DvxSdkPath, EntryPoint = "DVR_StartRealPlay", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 2 public static extern int StartRealPlay(int hUserHandle, Delegate callback);
3. 创建一个委托的实例
1 private RealCallback realCallBack = null;
4. 定义委托对应的函数
1 private void RealCallbackFun(int hRealHandle, int dwDataType, IntPtr lpReal, uint dwSize, IntPtr lpVoid) 2 { 3 4 }
5. 给委托赋值
1 realCallBack = RealCallbackFun;
6. 使用委托
1 StartRealPlay(handle, realCallBack);