Sorry if this is a common question but I'm struggling to make a start with C++ .NET and I'm not even sure what is newbie territory and what isn't.
I need to build some simple .NET forms that talk to a Fortran DLL. Data transfer is through arrays of doubles. The DLL developer has given me a simple VB6 interface to the DLL to help. Neither of us know anything much about .NET.
To take one exported function as an example, the VB access is as follows...
I want to pass an array of 25 doubles from C++ .NET to this function. I will also need to pull arrays of double back from other functions.
I have put my input parameters into an unmanaged array declared...
I access the DLL through Pinvoke as follows...
If I send an array as above, I get uninitialised garbage back (through the second function). If (mindful of the advice to send just the first element) I address the function as follows...
I get an exception 'Object reference not set to an instance of an object'.
I have looked at custom marshaling and my head is still spinning! Do I really need to massage an unmanaged array of doubles? Doesn't IJW take care of basic marshaling?
What is the correct way to send arrays of doubles to and from Fortran DLLs.
I'd be very grateful for any help.
TIA,
Alan
I need to build some simple .NET forms that talk to a Fortran DLL. Data transfer is through arrays of doubles. The DLL developer has given me a simple VB6 interface to the DLL to help. Neither of us know anything much about .NET.
To take one exported function as an example, the VB access is as follows...
Code:
'C Arguments:
'C dim a_dblInputData(1 to a_lngNumInputData) as double
'C (REMEMBER: pass only the first element of the array)
'C
Declare Function Set_InputData _
Lib "Test.dll" _
Alias "_set_inputdata@8" _
(ByVal a_lngNumInputData As Long, ByRef a_dblInputData As Double) _
As Long
I want to pass an array of 25 doubles from C++ .NET to this function. I will also need to pull arrays of double back from other functions.
I have put my input parameters into an unmanaged array declared...
Code:
double* dblIn = new double __nogc[25];
I access the DLL through Pinvoke as follows...
Code:
extern "C"
{
[DllImport("Test")]
int set_inputdata(int, double[]);
[DllImport("Test")]
int get_inputdata(int, double[]);
}
If I send an array as above, I get uninitialised garbage back (through the second function). If (mindful of the advice to send just the first element) I address the function as follows...
Code:
[DllImport("Test")]
int set_inputdata(int, double);
I get an exception 'Object reference not set to an instance of an object'.
I have looked at custom marshaling and my head is still spinning! Do I really need to massage an unmanaged array of doubles? Doesn't IJW take care of basic marshaling?
What is the correct way to send arrays of doubles to and from Fortran DLLs.
I'd be very grateful for any help.
TIA,
Alan