[英]Passing array as out parameter from c# using COM
我想使用COM調用具有以下簽名的函數:
void GetCompoundList(ref object compIds, ref object formulae, ref object names, ref object boilTemps, ref object molwts, ref object casnos)
我無權訪問實現,但是對象是Variant類型的對象,其中包含String和Double的SafeArrays,並且都是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是實現接口的類的實例。
但是,函數調用無效:調用后數組仍為null 。
C ++:
CComVariant cIdsM, cFormulaeM, cNamesM, cTempM, cWeiM, cCASM;
HRESULT hr = thermocompoundsMat->GetCompoundList(&cIdsM, &cFormulaeM, &cNamesM, &cTempM, &cWeiM, &cCASM);
知道我的C#代碼有什么問題嗎?
謝謝菲利普和漢斯。 實際上,我必須根據您的2條注釋進行修改以修復代碼。
object thermoCompounds = null;
object thermoCompFormulae = null;
object thermoCompName = null;
object thermoCompTemp = null;
object thermoCompWei = null;
object thermoCompCAS = null;
ppThermoComp.GetCompoundList(ref thermoCompounds, ref thermoCompFormulae, ref thermoCompName, ref thermoCompTemp, ref thermoCompWei, ref thermoCompCAS);
在問這個問題之前,我嘗試了每個對象 ( 對象和ref ),但分別...
順便說一句,傳遞Array類型時不使用ref進行編譯,但不使用ref關鍵字進行編譯,可能是因為Array已經是引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.