Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ VB
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.
 
[Edit]Code block added[/Edit]
Posted 16-Mar-13 6:54am
aoslo274
Edited 16-Mar-13 9:22am
ProgramFOX131.8K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The difference is between pass-by-value which makes a copy of the data and pass-by-reference which just passes the address of the original data and doesn't make a copy. The cost of copying the image likely explains the 5 times difference in speed but not why the two boards work differently or how that manages to affect your code.
I can only guess that one board has read-only memory for the image and the driver layer or something in the third party control you're using is smart enough to map a different function to getImageData which returns a reference rather than a copy. The use of let which determines the type of imageArray from the result type of Image.getImageData makes imageArray a reference type. The call to mathLib would also need to be to a different overload of or wrapper for the function, one which takes a reference. This is speculative but not impossible with VB6 late binding.
If you examine the binary interface of the third party Dll or capture driver with a tool like Depends it should be possible to see separate getImageData functions which return either a copy of the data or a reference/pointer to the data.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 Zoltán Zörgő 99
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 16 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100