Pass a ref array to the method in C# (which written in C++)

A

Alex

Hi All!
I have a dll, which is written in VC++.NET.
In the dll, I write a method like that
void SetData(double* array, int len)
.....

then, I use this dll in a C#-Application, trying to pass
double[] myArray = new double[10];
MyObj.SetData(myArray, 10);

it posted an error: Can not convert from 'doublt[]' to 'ref double'.
Pls help me to solve this problem!
thanks!
 
S

Shortgrey

Hi Alex
you can try

double[] myArray = new double[10];
unsafe
{
fixed(double *myPtr = myArray)
SetData(myPtr, 10);
}

with "Allow unsafe code blocks" configuration enable.
 
A

Alex

Thank Shortgrey!

but I don't know how my project has not worked yet, event I have done
anything as you guide

double[] x = new double[10];

double[] y = new double[10];



for (int i = 0; i < 10; i++)

{

x = i;

y = 10*i;


unsafe

{

fixed(double *xx = x)

fixed(double *yy = y)

myDllObj.SetData(xx, yy, 10, true);


}



The same error!






Shortgrey said:
Hi Alex
you can try

double[] myArray = new double[10];
unsafe
{
fixed(double *myPtr = myArray)
SetData(myPtr, 10);
}

with "Allow unsafe code blocks" configuration enable.
Hi All!
I have a dll, which is written in VC++.NET.
In the dll, I write a method like that
void SetData(double* array, int len)
....

then, I use this dll in a C#-Application, trying to pass
double[] myArray = new double[10];
MyObj.SetData(myArray, 10);

it posted an error: Can not convert from 'doublt[]' to 'ref double'.
Pls help me to solve this problem!
thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top