简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM