Pergunta

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).

Foi útil?

Solução 2

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);
}

Outras dicas

The declaration of the COM object's Frequencies() function matches the example in the document, except that the example uses SAFEARRAY(VARIANT) and your COM object uses SAFEARRAY(BSTR) instead. So try adapting the example code for strings, eg:

QList<QString> list;
...
QList<QVariant> parameters;
parameters << QVariant(list);
object->dynamicCall("Frequencies(QList<QString>&)", parameters);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top