Marshal float/double array at DLLImport of C++ function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?Tiago_Falc=E3o?=

    Marshal float/double array at DLLImport of C++ function

    I search on google, msdn,... and i not find no solutions. Any ideia?

    ----------------------------
    C++ Example Source:

    extern "C" __declspec(dlle xport)
    double * extract(int nrows,int ncols,int * RGB){
    int i=0;
    int j=ncols*nrows;
    double* x;
    x=(double*)call oc(1,sizeof(dou ble)); // I
    need return one double array
    x[0]=((double)RGB[0]+RGB[1]+RGB[2])/3;
    return x ;
    }

    extern "C" __declspec(dlle xport)
    double distance(double * img1, double* img2){
    return img1[0]-img2[0];
    }


    --------------------------
    C# code:

    [DllImport("C:/Users/tiago/Desktop/teste.dll")]
    [MarshalAs(Unman agedType.LPArra y, ArraySubType =
    UnmanagedType.R 8, SizeParamIndex = 1)]
    public static extern Double[] extract(int nrows, int ncols,
    int[] RGB);

    [DllImport("C:/Users/tiago/Desktop/teste.dll")]
    public static extern Double distance(Double[] img1, Double[]
    img2);

    ---------------------------
Working...