c#中如何调用C++中的“以引用作为参数”的函数
C++ 以引用作为参数的函数原型:Int paramscal(double *vsrc,double *csrc,double& Volt_freq,double&Volt_RMS,double&Curren_freq,double&Current_RMS,double&thata);
别人在C++中调用示例:
double *tempV=new double[2500];
double *tempC=new double[2500];
tempV=filtereddata(m_Power_V,1);
tempC=filtereddata(m_Power_C,1);
double Volt_freq;
double Volt_RMS;
double Curren_freq;
double Current_RMS;
double thata;
int aa=paramscal(tempV,tempC,Volt_freq,Volt_RMS,Curren_freq,Current_RMS,thata);
如果 aa==1则成功。
我在C#中的调用:
[DllImport("sigproc.dll", EntryPoint = "paramscal", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
unsafe public static extern int paramscal(double* vsrc, double* csrc, ref double Volt_freq, ref double Volt_RMS, ref double Curren_freq, ref double Current_RMS, ref double thata);
double[] tempV = ClassGetData.GetData(d,1);
double[] tempI = ClassGetData.GetData(d, 1);
fixed (double* k = &tempV[0])
{
fixed (double* k1 = &tempI[0])
{
//定义变量
double Volt_freq=50;
double Volt_RMS=50;
double Curren_freq=100;
double Current_RMS=10;
double thata=0;
int aa = paramscal(k, k1, ref Volt_freq, ref Volt_RMS, ref Curren_freq, ref Current_RMS, ref thata);
}
}
出现错误见附件: