110,539
社区成员
发帖
与我相关
我的任务
分享
__declspec(dllexport) void __stdcall functionA(
int* a,
int* b,
double *c,
double[] inputArr,
double* out,
void(*fun)(int*, int*,double[],double[])
)
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Test{
class Program
{
public delegate void costfun(ref int a, ref int b, double[] x, double[] fx);
static void Main(string[] args)
{
int a = 5, b = 3,
double c= 1e-14
double[] x = new double[5] { 1, 3, 5, 7, 9 };
double y=0;
costfun F = new costfun(funCSharp);
functionA(ref a, ref b, ref c, x,ref y Marshal.GetFunctionPointerForDelegate(F));
}
public static void funCSharp(ref int na, ref int nb, double[] inX, double[] outY)
{
int i = 0;
for (i = 0; i < outY.Length; i++)
{ outY[i] = outY[i] * outY[i]; }
}
// import the dll
[DllImport("cdll.dll", EntryPoint = "functionA", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern void functionA(int* a, int* b, double*c,double[] inputArr, double* out, IntPtr fcpointer);
}
}
public static void funCSharp(ref int na, ref int nb, double[] inX, double[] outY)
{
int i = 0;
for (i = 0; i < outY.Length; i++)
{ outY[i] = outY[i] * outY[i]; }
}