有一個外部的dll方法:傳遞正確的參數,以託管的DLL方法在C#
public unsafe static void BV([In] int* key, [In] int* m, [In] int* n, [In] double* a, [In] double* b, [In] double* bl, [In] double* bu, [Out] double* x, [Out] double* w, [In] double* act, [In] double* zz, [Out] double* istate, [Out] int* loopa)
我如何在C#中傳遞參數是要求* int和*雙和如何應對,出?
在示例代碼我不能傳遞參數的方法需要他們。什麼是錯的?
int key = 0, n = 2, m = 3;
double[] a = { 1.0, 2.0, 3.0, 4.0, 5.0 };
double[] b = { 10.0, 20.0, 30.0 };
double[] bl = { 0.0, 1.0 };
double[] bu = { 1.0, 2.0 };
double[] x = new double[n];
double[] w = new double[n];
double[] act = new double[m * (Math.Min(m, n) + 2)];
double[] zz = new double[m];
double[] istate = new double[n + 1];
int loopA = 0;
bvlsFortran.BV(key,m,n,a,b,bl,bu, x,w,act,zz,istate,loopA); //bvlsFortran is dll file
Console.WriteLine(loopA);
我與
bvlsFortran.BV(key,m,n,a,b,bl,bu, out x,out w,act,zz,out istate, out loopA);
也
bvlsFortran.BV(ref key,ref m,ref n,ref a,ref b,bl,bu, out x,out w,act,zz,out istate, out loopA);
嘗試,但他們似乎並不管用 我在做什麼錯
是否有可能利用它在安全的前提下,也許使用Marshal? – cMinor
@cMinor唯一的辦法避免使用不安全的代碼在C#中我知道,使用C++/CLI包裝器 – Uriil
你如何應用此技術來加倍*加倍[]?如雙* AP =(雙*)&a ...;是行不通的 – cMinor