private static extern int Calcular(delegateCalculoMatriz fp, delegateFuncaoResposta fr, int n, double tempo0, double passo, int numeroDePassos, IntPtr yPointer, IntPtr dyPointer, double tolRelativa, double tolAbsoluta, double passoInicial, double passoMaximo);
public bool Calcular(delegateCalculoMatriz delegateCalculo, out List<KeyValuePair<double, double[]>> resposta, out int codigoErro) { int size = Marshal.SizeOf(dy0[0])*dy0.Length; IntPtr dyPointer = Marshal.AllocHGlobal(size); IntPtr yPointer = Marshal.AllocHGlobal(size); Resposta = new List<KeyValuePair<double, double[]>>(); Resposta.Add(new KeyValuePair<double, double[]>(tempo0,y0)); try { // Copy the array to unmanaged memory. Marshal.Copy(y0, 0, yPointer, y0.Length); Marshal.Copy(dy0, 0, dyPointer, dy0.Length); } catch { // Free the unmanaged memory. Marshal.FreeHGlobal(yPointer); Marshal.FreeHGlobal(dyPointer); } int resp = Calcular(delegateCalculo,DelegateResposta, numeroDeIncognitas, tempo0, passoDeTempo,numeroDePassos, yPointer, dyPointer,ToleranciaRelativa,ToleranciaAbsoluta,PassoInicial,PassoMaximo); resposta = Resposta; Marshal.FreeHGlobal(yPointer); Marshal.FreeHGlobal(dyPointer); codigoErro = resp; if (resp == 0) return true; return false; }