예제 #1
0
 public ExvokerImpl(object o, DelegateStorage d, ICallingConventionAdapter a)
 {
     foreach (var sdt in d.DelegateTypes)
     {
         var del = Delegate.CreateDelegate(sdt.DelegateType, o, sdt.Method);
         Delegates.Add(del);                     // prevent garbage collection of the delegate, which would invalidate the pointer
         EntryPoints.Add(sdt.EntryPointName, a.GetFunctionPointerForDelegate(del));
     }
 }
 public IntPtr GetFunctionPointerForDelegate(Delegate d)
 {
     if (_slots == null)
     {
         throw new InvalidOperationException("This calling convention adapter was created for departure only!  Pass known delegate slots when constructing to enable arrival");
     }
     if (!_slots.TryGetValue(d, out var slot))
     {
         throw new InvalidOperationException("All callback delegates must be registered at load");
     }
     return(_waterboxHost.GetCallbackProcAddr(WaterboxWrapper.GetFunctionPointerForDelegate(d), slot));
 }