private unsafe static int TryExcelImpl12(int xlFunction, out object result, params object[] parameters) { int xlReturn; // Set up the memory to hold the result from the call XlOper12 resultOper = new XlOper12(); resultOper.xlType = XlType12.XlTypeEmpty; XlOper12 *pResultOper = &resultOper; // No need to pin for local struct // Special kind of ObjectArrayMarshaler for the parameters (rank 1) using (XlObjectArray12Marshaler.XlObjectArray12MarshalerImpl paramMarshaler = new XlObjectArray12Marshaler.XlObjectArray12MarshalerImpl(1, true)) { XlOper12 **ppOperParameters = (XlOper12 **)paramMarshaler.MarshalManagedToNative(parameters); xlReturn = Excel12v(xlFunction, parameters.Length, ppOperParameters, pResultOper); } // pResultOper now holds the result of the evaluated function // Get ObjectMarshaler for the return value ICustomMarshaler m = XlObject12Marshaler.GetInstance(""); result = m.MarshalNativeToManaged((IntPtr)pResultOper); // And free any memory allocated by Excel Excel12v(xlFree, 1, &pResultOper, (XlOper12 *)IntPtr.Zero); return(xlReturn); }
internal static IntPtr XlAddInManagerInfo12(IntPtr pXloperAction12) { Debug.WriteLine("In XlAddIn.XlAddInManagerInfo12"); ICustomMarshaler m = XlObject12Marshaler.GetInstance(""); object action = m.MarshalNativeToManaged(pXloperAction12); object result; if ((action is double && (double)action == 1.0)) { InitializeIntegration(); result = IntegrationHelpers.DnaLibraryGetName(); } else { result = IntegrationMarshalHelpers.GetExcelErrorObject(IntegrationMarshalHelpers.ExcelError_ExcelErrorValue); } return(m.MarshalManagedToNative(result)); }
internal static IntPtr RegistrationInfo(IntPtr pParam) { if (!_initialized) { return(IntPtr.Zero); } // CONSIDER: This might not be the right place for this. ICustomMarshaler m = XlObject12Marshaler.GetInstance(""); object param = m.MarshalNativeToManaged(pParam); object regInfo = XlRegistration.GetRegistrationInfo(param); if (regInfo == null) { return(IntPtr.Zero); // Converted to #NUM } return(m.MarshalManagedToNative(regInfo)); }