11-18-2004 10:07 AM
12-30-2004 11:00 AM
03-10-2005 02:06 PM
@rolfk wrote:
There is one problem with this. SAFEARRAYS are not directly compatible with LabVIEW datatypes. So what is actually happening is that LabVIEW passes in a variant to the COM library and that takes it and puts in a SAFEARRAY. Then when you try to convert the SAFEARRAY variant into a LabVIEW array what actually happens is that LabVIEW creates a new native LabVIEW array handle and copies all the data from the SAFEARRAY variant into it and then disposes the COM variant altoghether.
There is no way LabVIEW could directly continue to use a SAFEARRAY in its diagram as the according memory management is quite different between COM objects and LabVIEW data types. So this copy is basically inavoidable due to different memory management paradigmas between COM and LabVIEW.
If you new the buffer size needed by your COM DLL beforehand and had a function where you could simply pass a LabVIEW preallocated float* array pointer into, this would be no problem at all.
Rolf Kalbermatter
03-10-2005 04:02 PM
Our new COM method on this interface is shown below:
HRESULT FetchDataLV([in, out] float* DataBuffer, [in, defaultvalue(0)] long DesiredScans, [out, retval] long* ReturnedScans);
The problem is that Labview thinks the first parameter is a reference to a single item as opposed to an array. Since it is a COM method, there seems to be no way to specify the argument types as you can when calling a C DLL---everything is determined by the type library. Is there any way I can convince Labview that the first parameter is an array of floats rather than a a single float passed by reference?
Thanks for any insight you may have,
Eric Gross
03-11-2005 09:40 AM
@rolfk wrote:
The problem is the type library generation and that is done by your compiler environment. LabVIEW takes whatever the type library says. I have no experience with type libraries nor COM programming myself.
One thing I could think of is declaring your function as:
HRESULT FetchDataLV([in, out] float DataBuffer[], [in, defaultvalue(0)] long DesiredScans, [out, retval] long* ReturnedScans);
In C
float DataBuffer[] == float* DataBuffer
but the type library generator MAY make a difference on these two.
Rolf Kalbermatter