how to save the ARRAY returned by C DLL from C sharp


i new programing ...

i want save array returned c dll c sharp array

my code fallows

1.c dll

 

       extern "c"
       {
           __declspec(dllexport)
int* main(int a1[], int a2[] ,int row1,int col1,int col2)

{
   
   ................................

................................

................................

int * =(int) malloc(sizeof(int)*k);

...........................

return a;

}

}

 

and c sharp program fallows.

 [dllimport("f:\\just it\\cuda\\gpumul\\gpumulgui\\resource\\gpumul.dll")]
        [return: marshalas(unmanagedtype.lparray )]
        public static extern intptr main(int[] k1, int[] k2, int x, int y, int z);
 public static int[] getarray()
        {
           
            int size = 10
            int x = 8
            int y = 7
            int z =8

          intptr array = main(matrixone, matrixtwo, x, y, z);-----------------run time error here  "int/uint must paired sysint or sysuint).
           
            int[] marray = new int[size];
            marshal.copy(array, marray, 0, size);                                 // plz check this
            //  marshal.freehglobal(array); //free unmanaged array
           
            return marray;
        }                     

 

remove marshalas attribute.


.NET Framework  >  Common Language Runtime Internals and Architecture



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'