简体   繁体   English

C ++ COM [in,out] safearrays

[英]C++ COM [in, out] safearrays

I need to call a COM function in C++ that returns a reference to a SAFEARRAY(BSTR) . 我需要在C ++中调用一个COM函数,该函数返回对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 . 但list元素保持为10.0

Am I missing something? 我想念什么吗?

EDIT 编辑

I used Oleview.exe and actually, the function looks like this: void Frequencies(VARIANT* FrequencyArray); 我使用了Oleview.exe,实际上,该函数如下所示: 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) . 但是ActiveX服务器的文档说: 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. COM对象的Frequencies()函数的声明与文档中的示例匹配,但该示例使用SAFEARRAY(VARIANT)而您的COM对象使用SAFEARRAY(BSTR)代替。 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 . 我必须阅读parameters的第一个元素,然后将其转换为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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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