02-17-2006 02:53 PM
02-17-2006 03:46 PM
02-19-2006 05:49 AM
02-20-2006 10:58 AM - edited 02-20-2006 10:58 AM
I have successfully passed a cluster with another cluster to a DLL using the following code. The cluster must be unbundled and then bundled as shown. Strings must be changed to byte arrays, and arrays must be changed into clusters. It probably depends on how the DLL is written also.
tst: I used your block diagram capture tool. WOW, what a time saver. Thanx again (also to CC, Altenbach, JPD,.....)
Message Edited by tbob on 02-20-2006 09:59 AM
Message Edited by tbob on 02-20-2006 10:01 AM
02-21-2006 07:56 AM
02-21-2006 10:14 AM
02-21-2006 11:37 AM
That is not entirely correct. LabVIEW stores flat data the same way as C. Flat data is anything that does not contain a string or an array. There may be alignment issues (LabVIEW always uses byte packing) whereas external code can use whatever packing the programmer chose either through compiler settings or specific #pragma pack() statments in the code, but for the rest flat data is exactly the same in both LabVIEW and C.
@tbob wrote:
Labview clusters are not stored in the same binary format as C structures. So you can't just pass the cluster, C would not recognize the format as a structure. In my previous post, I showed how to unbundle, re-structure the cluster elements, then bundle again. This puts it in a binary form similar to a C structure. Adapt to Type can then work properly to convert the cluster into a C structure. Strings must be converted to byte arrays then to clusters. Any 1D array must be converted to a cluster. You can't pass 2D arrays at all, you must separate each row and pass each one as a 1D array converted to a cluster separately. It all comes down to how the languages store the data type in binary format.
02-21-2006 12:52 PM
I wasn't talking about flat data, I was comparing the way Labview stores a cluster to the way C stores a structure. What I mean is that Labview may store the number of elements first, then the elements, and so on. I am not quite sure exactly how LV does it but I do know that C stores structures differently. If it did, it would be quite easy to pass a Labview cluster to a C structure.
Whatever the case, I am able to pass LV clusters successfully to and from C structures in a DLL using the methods I described earlier, without use a wrapper. Again it may depend on the DLL and how it was written.
02-21-2006 01:37 PM
As always rolf is on track. He explained better what i meant earlier, the main problem when passing clusters in a DLL is the case when you have in the C structure a pointer to variable sized arrays (numeric or string), otherwise the passing is quite straight. Actually in the code from tbob when the “array to cluster “is used a cluster of fixed size is created so the above problem is avoided, so in the initial cluster tbob considers that the string and the U8 array has fixed sizes.
cosmin
02-21-2006 01:54 PM