我有一个我尝试调用的COM方法,其中有一个类型' object'它必须是2D双安全阵列,纬度/长点的集合。如何在JACOB中创建SafeArray以通过COM接口发送?
我尝试将2D数组作为对象传递到对象列表中。该方法不会返回错误,但我没有看到FalconView中的结果(渲染多边形)。
double polyPoints[][] = new double[5][2];
polyPoints[0][0] = 75.3;
polyPoints[0][1] = 4.5;
polyPoints[1][0] = 3.8;
polyPoints[1][1] = 4.8;
polyPoints[2][0] = 2.3;
polyPoints[2][1] = 2.5;
polyPoints[3][0] = 5.3;
polyPoints[3][1] = 6.5;
polyPoints[4][0] = 0.3;
polyPoints[4][1] = -1.5;
// Can't recreate Variant or SafeArray from double[x][y] array;
Object[] polygonArgs = new Object[] {m_mainLayerHandle, polyPoints, 1};
Variant returnAddPolygon = Dispatch.invoke(mainLayerDispatch, "AddPolygon", Dispatch.Method, polygonArgs, new int[1]);
System.out.println("Polygon Handle: " + returnAddPolygon.getInt());
Object[] refreshArgs = new Object[] {m_mainLayerHandle};
Variant refreshVariant = Dispatch.invoke(mainLayerDispatch, "Refresh", Dispatch.Method, refreshArgs, new int[1]);
第二篇文件:
lat_lon_array 二维SAFEARRAY双打。第一个维度包含纬度值。第二个维度包含经度值
答案 0 :(得分:0)
似乎SafeArray使用一些有些不清楚的构造函数支持1维,2维和N维数组。鉴于我在上面创建的2D双数组,我能够将数据复制到2D双安全阵列中。在前面创建double [] []肯定会更有效,但我在一些原型代码中这样做。可能有办法将整个数组复制到安全数组中......我不确定。
// 2D array of type double. First dimension size 5, second dimemnsion size 2.
SafeArray safeArray = new SafeArray(Variant.VariantDouble, 5, 2);
for(int i = 0; i < 5; i++) {
for (int j = 0; j < 2; j++) {
// set the value of safearray[i][j] to value polyPoints[i][j]
safeArray.setDouble(i, j, polyPoints[i][j]);
}
}