Right, what is needed sounds simple, but it is proving to be a real pain.
I have some GUI code in C# (note i've never used C# before but familiar with the syntax) and I have C++ code which interacts with it using CLI.
In C#, I want to create an array of doubles, and send it to my C++ code. I'm using the code below as the means of passing an array, and this complies in isolation.
So from C# im passing in a double[] array into that function.
public ref class KernelWrapper
{
public:
static void ImageNoiseFilter(System::IntPtr imageData, int imageWidth, int imageHeight, array<double>^ values);
What parameter type should I use to retrieve this array from the C++ side?
I've tried:
MyFunction(double values[]){}
MyFunction(double* values){}
MyFunction(array<double>^ values){}
but none compile, usually with the message of "array is not a template" for the last one, and
Error 1 error C2664: 'RunImageNoiseFilterKernel' : cannot convert parameter 4 from 'cli::array<Type> ^' to 'double *'
Any tips on how this achieve this will be greatly appreciated.
For readability, I'm updating with code up here
.cpp file:
void Bangor::KernelWrapper::ImageNoiseFilter(System::IntPtr imageData, int imageWidth, int imageHeight, pin_ptr<double> pval){
RunImageNoiseFilterKernel((Format24bppRgb*)((int)imageData), imageWidth, imageHeight); //If parameter would work, 4th argument would also be passed into this.
}
C# code:
double[] randomValues = new double[ARRAY_LENGTH]; //Array of random numbers
KernelWrapper.ImageNoiseFilter(ptr, image.Width, image.Height, randomValues);
The errors are:
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*'
Hope this clarifies a little.
clinamespace toarray<double>^? Like this:cli::array<double>^ values. Note that there also is astd::array. Perhaps a namespace clash because ofusing namespace-directives?Error 1 error : name followed by "::" must be a class or namespace nameis the result of that, followed by lots of expected a ")" errors. If you meant insideImageNoiseFilerit makes no difference./clroption? I assume you're compiling from within VS. If so, the appropriate options should be buried somewhere in [your-project]->properties.error : name followed by "::" must be a class or namespace nameerror : expected an identifiererror : invalid combination of type specifierserror : expected a ")"those are the errors I get using the 3rd. /clr is being used, yes.