I know this is the way to write floating point array
Variant Data;
DateTime CurrentTime;
CurrentTime.now();
double* ArrayVar;
Data.SafeArrayAccessData(Data.parray, reinterpret_cast<void**>(&ArrayVar));
std::memcpy(ArrayVar, Values.data(), Values.size() * sizeof(double));
SafeArrayUnaccessData(Data.parray);
ItemValues.emplace_back(new ValueQT((Data), EnumQuality_QUALITY_NOT_SET, CurrentTime));
ItemNames.emplace_back(ItemName);
ItemPaths.emplace_back(L"");
// auto Session = new DaSession(URL);
Session->write(Items, Paths, const_cast<std::vector<ValueQT*>&>(Values), WriteResults, &ExecutionOptions_);
But how do I prepare a string array for writing? The following code will just crash.
wchar_t** Temp = new wchar_t*[Size];
for (int j = 0; j < Size; j++)
{
Temp[j] = new wchar_t[Values[j].size() + 1 ];
std::wcscpy(Temp[j], Values[j].c_str());
}
wchar_t** ArrayVar;
Data.SafeArrayAccessData(Data.parray, reinterpret_cast<void**>(&ArrayVar));
std::memcpy(ArrayVar, Temp, Size * sizeof(wchar_t*));
for (size_t j = 0; j < Size; j++)
{
std::wcscpy((ArrayVar[j]), (Temp[j]));
}
Data.SafeArrayUnaccessData(Data.parray);
I need to use the OPC toolkit from https://github.com/SoftingIndustrial/OPC-Classic-SDK
The program also crashes if i don't use the for loop, with the same error message. Also the values are not set for ValueQT (with the string array).
If someone ever needs this here is a working solution: