I have been puzzled by the problem for days now, and any help is sincerely appreciated.
I use VB6 to control an imaging board to grab images from a CCD camera. I then pass the pixel data, which is in the form of a 2D Integer array, to a C++ function to do some processing (centroiding). The function resides in a dll named 'mathLib'.

The signature of the C++ function is:
STDMETHODIMP Cmath::centroid(VARIANT *image, short width, short height, VARIANT *theCentroid) ;

The context in VB6 is as follows:
'Image' is an activeX object embodying the image grabbed from the imaging board. Image.getImageData returns a 2D Integer array containing the pixel values of the image

To call the C function, I do:
dim centroid as variant
dim imageArray as variant
let width = Image.getImageWidth
let height = Image.getImageHeight
let imageArray = Image.getImageData 'get the pixel value array
Let centroid = mathLib.centroid(imageArray, width, height) 'call the C++ function

I tried 2 imaging boards from 2 different companies. The pixel data array in VB6 look the same - both are 2D Integer arrays of size 1024x1024. However when the array is passed to the C++ routine, there is a 5 times difference in processing speed. I examined the array on the C++ side, and noticed that the VT field has different values. One is 0x6002 (i.e. VT_BYREF & VT_ARRAY & VT_I2) and the other is 0x2002 (i.e. VT_ARRAY & VT_I2). I believe this is where the problem originates.

Can someone tell me how this comes to be? Where and how is the VT field of the 'imageArray' set when it's passed from VB6 to VC++? Notice that there is no extra processing in my code between getting the imageArray and calling the C++ function.