将double [,]转换为Variant *

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将double [,]转换为Variant *相关的知识,希望对你有一定的参考价值。

在我的应用程序中,我试图从我的WPF应用程序调用ATL COM类的函数。 ATL COM类的函数参数是这样的。

[id(5)] HRESULT GetFormationZPoints([in] BSTR sLyrName, [in,out] VARIANT* pLandingPoints);

在WPF方面,我试图像这样传递一个双的2-D数组

List<PointsVector> landingPoints = Planner.LandingPointsList;
double[,] dLPs = new double[landingPoints.Count, 3];
int i = 0;
foreach (PointsVector v in landingPoints)
{
    dLPs[i, 0] = v.X;
    dLPs[i, 1] = v.Y;
    dLPs[i, 2] = v.Z;
    i++;
}
gaInfo.GetFormationZPoints(targetReservoir.TargetLayerName, ref dLPs);

我收到以下错误消息:

参数2:无法从'ref double [,]'转换为'ref对象

答案

如异常中所述,您可以将dLP变量转换为object并查看它是否有效。基本上它应该看起来像,

    gaInfo.GetFormationZPoints(targetReservoir.TargetLayerName, ref (object) dLPs);

以上是关于将double [,]转换为Variant *的主要内容,如果未能解决你的问题,请参考以下文章