I have a COM method I'm trying to invoke, where there's an argument of type 'object' which must be a 2D double safe array, a collection of lat/long points. How can I create a SafeArray in JACOB to send through the COM interface?
I've tried just passing a 2D array as an object in the object list. The method doesn't return error, but I do not see the results I expect in FalconView (rendering of the polygon).
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]);
The second arument documentation:
lat_lon_array a two dimensional SAFEARRAY of doubles. The first dimension contains the latitude values. The second dimension contains the longitude values
It seems that SafeArray supports 1 Dimensional, 2 Dimensional, and N-Dimensional arrays using some somewhat unclear constructors. Given the 2D double array I created above, I was able to copy the data in to a 2D Double Safe Array. It would certainly be more efficient to create the double[][] up front, but I'm doing this in some prototype code. There may be ways to copy entire arrays in to the safe array... I am not sure.