That's right, what you need sounds simple, but it turns out to be a real pain.
I have GUI code in C # (note that I have never used C # before, but was familiar with the syntax), and I have C ++ code that interacts with it using the CLI .
In C #, I want to create an array of doubles and send it to my C ++ code. I use the code below as a means of transmitting an array, and this runs in isolation.
So, from C # im passing into the double [] array to this function.
public ref class KernelWrapper
{
public:
static void ImageNoiseFilter(System::IntPtr imageData, int imageWidth, int imageHeight, array<double>^ values);
What type of parameter should be used to extract this array from C ++?
I tried:
MyFunction(double values[]){}
MyFunction(double* values){}
MyFunction(array<double>^ values){}
, " " ,
Error 1 error C2664: 'RunImageNoiseFilterKernel' : cannot convert parameter 4 from 'cli::array<Type> ^' to 'double *'
, , .
.cpp :
void Bangor::KernelWrapper::ImageNoiseFilter(System::IntPtr imageData, int imageWidth, int imageHeight, pin_ptr<double> pval){
RunImageNoiseFilterKernel((Format24bppRgb*)((int)imageData), imageWidth, imageHeight);
}
#:
double[] randomValues = new double[ARRAY_LENGTH];
KernelWrapper.ImageNoiseFilter(ptr, image.Width, image.Height, randomValues);
:
Error 1 error C3824: 'cli::pin_ptr<Type>': this type cannot appear in this context (function parameter, return type, or a static member)
Error 3 The best overloaded method match for 'Bangor.KernelWrapper.ImageNoiseFilter(System.IntPtr, int, int, double*)' has some invalid arguments
Error 4 Argument 4: cannot convert from 'double[]' to 'double*'
, .