Passing multi dimension array to a DLL

Hi everyone,

I am trying to write a simple test dll that will be called from a program written in MQL4. In MQL I create a two dimension array and want to pass it to a C++ funcion. This function will then modify some elements in the array and I want to be able to view these changes in the calling program.

I can do it with a single dimension array but I am well and truly stuck trying to get it to work with a two dimension array.

At the time that the function is called I know the number of columns in the array but I don't know how many rows there will be.

This is my simple test code
1
2
3
4
5
6
7
8
9
 #define MT4_EXPFUNC __declspec(dllexport)

MT4_EXPFUNC void _stdcall ArrayTestingFunction(double* testArray)
{
	double value = testArray[1][1];

	// Change the value in  the array and check for the new value in the calling EA
	testArray[1][1] = value * 2;
}


This is the error I get when I try to compile the DLL
error C2109: subscript requires array or pointer type

If I hold the cursor over the word testArray I get the message "expression must have pointer-to-object type" displayed

Thanks in advance for your help

John
> At the time that the function is called I know the number of columns in the array
Only when you call it?

Or when you compile it?

Because compile-time 2D arrays are dead easy.
 
MT4_EXPFUNC void _stdcall ArrayTestingFunction(double (*testArray)[NUMCOLS])


> but I don't know how many rows there will be.
That's fine, because C doesn't care either.

So one would normally do this, so your function has effective bounds checking.
 
MT4_EXPFUNC void _stdcall ArrayTestingFunction(double (*testArray)[NUMCOLS], size_t numRows)



Sorry Salem_c

Or when you compile it?

I know the number of columns at compile time

Topic archived. No new replies allowed.