Hello
I need to write a function that will pass 2 parameters to a dll function. The dll function is below:
getADCSamplesFromAllEnabledChannels(int sampleToCapture, double **voltagePointerArray)
it takes a pointer to pointer as a parameter and i cannot think of the syntax to pass the pointer to pointer!
ANy suggestion is welcomed =) I can do this for a parameter that is just a pointer, sth like *voltagePointerArray, but not the **voltagePointerArray!
Thanks
Muhu

2 answers
The unmanaged function is expecting a double array to be passed by reference so I'd use from C#:
getADCSamplesFromAllEnabledChannels(int sampleToCapture, ref IntPtr voltagePointerArray)
You'll then need to copy your managed double array to an unmanaged buffer and pass the IntPtr to the buffer by reference to the unmanaged function.
Edit (to include sample code)
Suppose the unmanaged function is expecting the double array to be of length 'size'. The C# code to marshal the array to a buffer and call the unmanaged function would then be:
answered 2 years ago by:
17279
You'll then need to copy your managed double array to an unmanaged buffer and pass the IntPtr to the buffer by reference to the unmanaged function.
I am not sure what you meant by the above!
For a function like getSingleDACVoltage(byte dacNumber, double* voltage) in the dll, i use the following code:
unsafe void Get_Single_DAC_Voltage(TextBox tb_OutputNumber_DAC, TextBox tb_Voltage_DAC)
{
byte[] DAC_OutputNumber = new byte[1];
double[] DAC_Voltage = new double[1];
fixed (byte* DAC_OutputNumberPtr = DAC_OutputNumber)
fixed (double* DAC_VoltagePtr = DAC_Voltage)
{
bool got;
got = digitalIODll.getSingleDACVoltage((byte)(DAC_OutputNumberPtr), DAC_VoltagePtr);
if (got == true)
{
//tb_OutputNumber_DAC.Text = String.Format("{0,5:000}", DAC_OutputNumber[0]);
tb_Voltage_DAC.Text = String.Format("{0,5:000}", DAC_Voltage[0]);
}
else
{
MessageBox.Show("Could not get the DAC Voltage");
}
}
}
Thanks
Muhu
answered 2 years ago by:
0
17279
I've edited my answer to include some sample code.