我想使用 COM 调用具有以下签名的函数:
void GetCompoundList(ref object compIds, ref object formulae, ref object names, ref object boilTemps, ref object molwts, ref object casnos)
我无权访问实现,但对象是包含 String 和 Double 的 SafeArrays 的 Variant 类型,并且都是 out 参数。
这是我声明数组和调用函数的方式:
Array thermoCompounds = null;
Array thermoCompFormulae = null;
Array thermoCompName = null;
Array thermoCompTemp = null;
Array thermoCompWei = null;
Array thermoCompCAS = null;
ppThermoComp.GetCompoundList(thermoCompounds, thermoCompFormulae, thermoCompName, thermoCompTemp, thermoCompWei, thermoCompCAS);
其中 ppThermoComp 是实现接口的类的实例。
但是,函数调用没有效果:调用后数组仍然为空。
- 如果我以正确的大小初始化数组,则没有变化:该函数也没有效果
- 如果我使用不同的参数(例如返回的数组)从同一个 COM 接口调用另一个函数,它可以工作
- 如果我从 C++ 代码(仍然通过 COM)调用这个函数,它可以工作
C++:
CComVariant cIdsM, cFormulaeM, cNamesM, cTempM, cWeiM, cCASM;
HRESULT hr = thermocompoundsMat->GetCompoundList(&cIdsM, &cFormulaeM, &cNamesM, &cTempM, &cWeiM, &cCASM);
知道我的 C# 代码有什么问题吗?