当Variant从VB6传递到VC ++时,如何设置VT字段? [英] How is the VT field set when a Variant is passed from VB6 to VC++?

查看:64
本文介绍了当Variant从VB6传递到VC ++时,如何设置VT字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经对这个问题感到困惑了好几天了,真心感谢任何帮助。

我用VB6来控制成像板从CCD相机中抓取图像。然后,我将像素数据(以2D整数数组的形式)传递给C ++函数进行一些处理(centroiding)。该函数位于一个名为''mathLib''的DLL中。



C ++函数的签名是:

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) ;



VB6中的上下文如下:

''Image''是一个activeX对象,它包含从成像板中抓取的图像。 Image.getImageData返回一个包含图像像素值的2D整数数组



要调用C函数,我这样做:


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
...



我试过2个2个成像板differen公司。 VB6中的像素数据阵列看起来相同 - 都是尺寸为1024x1024的2D整数数组。但是,当数组传递给C ++例程时,处理速度有5倍的差异。我检查了C ++端的数组,发现VT字段有不同的值。一个是0x6002(即VT_BYREF& VT_ARRAY& VT_I2),另一个是0x2002(即VT_ARRAY& VT_I2)。我相信这是问题的根源所在。



有人能告诉我这是怎么回事吗?从'VB6传递到VC ++时,'imageArray'的VT字段在何处以及如何设置?请注意,在获取imageArray和调用C ++函数之间,我的代码中没有额外的处理。



添加的代码块[/ Edit]


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.

Code block added[/Edit]

推荐答案

区别在于传递值,它传递数据的副本和传递引用,它只是传递原始数据的地址而不是复印件。复制映像的成本可能解释了速度差异的5倍,但不是两个板的工作方式不同或者如何影响代码的原因。

我只能猜测一块主板有图像的只读内存,而你正在使用的第三方控件中的驱动程序层或其他东西足够聪明,可以将不同的函数映射到getImageData返回引用而不是副本。使用从结果类型 Image.getImageData中确定 imageArray 的类型使 imageArray 引用类型。对mathLib的调用还需要是函数的不同重载或包装器,它需要引用。这是推测性但不是不可能的VB6后期绑定。

如果你用Depends之类的工具检查第三方Dll或捕获驱动程序的二进制接口,应该可以看到单独的getImageData函数返回数据的副本或数据的引用/指针。
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.


这篇关于当Variant从VB6传递到VC ++时,如何设置VT字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆