// This is the main conversion function called from XlLibrary.RegisterMethods // targets may be null - the typical case // Either methods or lambdaExpressions may be null // If they are both supplied, then the corresponding entries in the lists must be null in one of the lists public static List <XlMethodInfo> ConvertToXlMethodInfos(List <MethodInfo> methods, List <object> targets, List <LambdaExpression> lambdaExpressions, List <object> methodAttributes, List <List <object> > argumentAttributes) { List <XlMethodInfo> xlMethodInfos = new List <XlMethodInfo>(); var count = methods?.Count ?? lambdaExpressions.Count; for (int i = 0; i < count; i++) { MethodInfo mi = methods?[i]; // List might be null object target = targets?[i]; // List might be null LambdaExpression lambda = lambdaExpressions?[i]; // List might be null object methodAttrib = (methodAttributes != null && i < methodAttributes.Count) ? methodAttributes[i] : null; List <object> argAttribs = (argumentAttributes != null && i < argumentAttributes.Count) ? argumentAttributes[i] : null; try { XlMethodInfo xlmi = new XlMethodInfo(mi, target, lambda, methodAttrib, argAttribs); // Skip if suppressed if (xlmi.ExplicitRegistration) { Logger.Registration.Info("Suppressing due to ExplictRegistration attribute: '{0}.{1}'", mi.DeclaringType.Name, mi.Name); continue; } xlMethodInfos.Add(xlmi); } catch (DnaMarshalException e) { Logger.Registration.Error(e, "Method not registered due to unsupported signature: '{0}.{1}'", mi.DeclaringType.Name, mi.Name); } } Parallel.ForEach(xlMethodInfos, xlmi => XlDirectMarshal.SetDelegateAndFunctionPointer(xlmi)); return(xlMethodInfos); }
internal static void XlAutoFree12(IntPtr pXloper12) { // CONSIDER: This might be improved.... // Another option would be to have the Com memory allocator run in unmanaged code. // Right now I think this is OK, and easiest from where I'm coming. // This function can only be called after a return from a user function. // I just free all the possibly big memory allocations. XlDirectMarshal.FreeMemory(); }
internal static IntPtr RegistrationInfo(IntPtr pParam) { if (!_initialized) { return(IntPtr.Zero); } object param = XlMarshalContext.ObjectParam(pParam); object regInfo = XlRegistration.GetRegistrationInfo(param); if (regInfo == null) { return(IntPtr.Zero); // Converted to #NUM } var ctx = XlDirectMarshal.GetMarshalContext(); return(ctx.ObjectReturn(regInfo)); }