Search code examples
c++qtcomsafearrayqaxobject

C++ COM [in, out] safearrays


I need to call a COM function in C++ that returns a reference to a SAFEARRAY(BSTR).

According to this document, it should be:

QAxObject object = new QAxObject(...);
QStringList list;

for(int i=0; i<goodSize; i++)
    list << "10.0";

object->dynamicCall("Frequencies(QStringList&)", list);

for(int i=0; i<list.size(); i++)
    qDebug() << list.at(i);

but the list elements remain to 10.0.

Am I missing something?

EDIT

I used Oleview.exe and actually, the function looks like this: void Frequencies(VARIANT* FrequencyArray);.

But the documentation of the ActiveX server says: Use a safearray of strings (VT_BSTR) or reals (VT_R8 for double or VT_R4 for float).


Solution

  • Found the problem. It was the way to read the results. I had to read the first element of parameters then convert it to a QStringList. I am angry against me :(

    IBKDataSet *data = function->FunctionData();
    int nbFrequencies = data->dynamicCall("GetNumberOfXAxisEntries()").toInt();
    QList<QString> frequencies;
    for(int i=0; i<nbFrequencies; i++) {
        frequencies << "0.0";
    }
    QList<QVariant> parameters;
    parameters << QVariant(frequencies);
    data->dynamicCall("Frequencies(QList<QString>&)", parameters);
    frequencies = parameters.first().toStringList();
    for(int j=0; j<frequencies.size(); j++) {
        qDebug() << frequencies.at(j);
    }