MultiCharts64 problem accessing dynamic arrays in extension DLL

Questions about MultiCharts and user contributed studies.
rjelles
Posts: 36
Joined: 04 Feb 2010
Location: Calgary, AB Canada
Has thanked: 7 times
Been thanked: 19 times
Contact:

MultiCharts64 problem accessing dynamic arrays in extension DLL

Postby rjelles » 05 Mar 2021

I'm having problems accessing data in a dynamic array that is being passed to our extension DLL. The associated array variable can be correctly accessed in the extension function by passing the array name, and the returned dimensions and sizes are correct. All of this is fine.

When the calling function uses a fixed array (eg Arrays: myData[2,24]), then I can access and copy all of the data in the array correctly, but since our array sizes are unknown at compile time, we really need to use dynamic arrays.

There appears to be some differences in implementation for MC64 handling of dynamic arrays vs the TS docs, so my question is: can you confirm the correct steps to access data in a dynamic array?

The following code snippet is based on the method outlined in the TS Extension guide for use with dynamic arrays, but it fails because it is expecting a handle to be returned from pELInputArray, but is just getting a data value.

Code: Select all

enDataType dt = pELInputArray->DataType; // dtDouble for fixed and dynamic! if (dt == dtHandle) { // According to my understanding of the TS docs, // pELInputArray->DataType should be a dtHandle type for dynamic arrays // and this call should return the value of the handle: int handle = pELInputArray->GetAsInteger(0); // should return dynamic array handle, but is 0 // since the handle is 0, this fails: if (pELObj->System->Array->IsValidHandle(handle)) // <<== causes COM exception { IELFrameworkArrayPtr pDynArray = pELObj->System->Array; for (int i = 0; i < input_sz; i++) { inputs[i] = pDynArray->GetFloatValue(handle, i); } } }

When I change the array to a fixed size, I can access the array correctly using this snippet:

Code: Select all

for (int i = 0; i < input_sz; i++) { pELInputArray->SelectedIndex[0] = i; inputs[i] = pELInputArray->GetAsDouble(0); }



// This is the entire function

Code: Select all

extern "C" __declspec(dllexport) TestDynamicArrays(IEasyLanguageObject * pELObj, LPSTR Input_Array_Name) { // Find the EL variable for the passed array name IEasyLanguageVariable* pELInputArray = pELObj->Variables[(char*)Input_Array_Name]; // Get the array shape int input_dim = pELInputArray->Dimensions; int input_sz = pELInputArray->DimensionSize[0]; double * inputs[input_sz]; // Copy data from the input array to our internal array // This works if the array has fixed dimensions, // but generates a COM error for dynamic arrays (SEE Below) for (int i = 0; i < input_sz; i++) { pELInputArray->SelectedIndex[0] = i; inputs[i] = pELInputArray->GetAsDouble(0); } // -------------------------------------------------------------------- // Dynamic Array handling // This is how I understand data in dynamic arrays should be accessed // based on the TS EL Extension Guide // -------------------------------------------------------------------- // The variable DataType should be dtHandle for Dynamic arrays, but // in MC64, it is the array data type (eg. dtDouble) enDataType dt = pELInputArray->DataType; // dtDouble for fixed and dynamic! if (dt == dtHandle) { int handle = pELInputArray->GetAsInteger(0); // should return dynamic array handle, but is 0 // handle should point to the dynamic array entry, // but is 0, so this next statement will fail if (pELObj->System->Array->IsValidHandle(handle)) // <<== causes COM exception { IELFrameworkArrayPtr pDynArray = pELObj->System->Array; for (int i = 0; i < input_sz; i++) { pELInputArray->SelectedIndex[1] = i; inputs[i] = pDynArray->GetFloatValue(handle, i); } } } } This is the exception: Exception thrown at 0x00007FFE23219689 in MultiCharts64.exe: Microsoft C++ exception: _com_error at memory location 0x00000000302CDCA8. Exception thrown at 0x00007FFE23219689 in MultiCharts64.exe: Microsoft C++ exception: _com_error at memory location 0x00000000302CDD00. Exception thrown at 0x00007FFE23219689 in MultiCharts64.exe: Microsoft C++ exception: _ELAPI_::_ELAPI_exception_Resolve at memory location 0x00000000302CE090. Exception thrown at 0x00007FFE23219689 in MultiCharts64.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFE23219689 in MultiCharts64.exe: Microsoft C++ exception: _ELAPI_::_ELAPI_exception_Resolve at memory location 0x00000000302CE090. Exception thrown at 0x00007FFE23219689 in MultiCharts64.exe: Microsoft C++ exception: _ELAPI_::_WithSender_exception<IExceptionSender const ,_ELAPI_::_ELAPI_exception_Resolve> at memory location 0x00000000302CECF0.

User avatar
Kate MultiCharts
Posts: 575
Joined: 21 Oct 2020
Has thanked: 7 times
Been thanked: 144 times

Re: MultiCharts64 problem accessing dynamic arrays in extension DLL

Postby Kate MultiCharts » 16 Mar 2021

Hello rjelles,

Please send us (support@multicharts.com) the following files, so that we could reproduce the issue to analyze it on our end:

1. Your DLL
2. Your indicator in PLA format
3. Your workspace
4. The steps to reproduce the issue


Return to “MultiCharts”