Well, I don't think NI should spend much time on this. The
configuration screen necessary to configure all those options really
would be a mess to deal with and you would still need to know all the
detail knowledge about C data types, how they are passed between
functions, particular byte boundary alignement etc.

Without this knowledge present you still couldn't use these options
and once you have the knowledge, writing a simple wrapper DLL which
goes between LabVIEW and your complicated data structure and possibly
callback API is actually much simpler than trying to configure and
possible wire your API interface in LabVIEW.

Of course knowing the layout of the LabVIEW data structures you can
basically use a trick to get the pointer to a LabVIEW string into a
data structure to be passed to a DLL but it is still far from simple.
The callback pointer however can't be tricked from a LabVIEW diagram
(at least not without so much magic that writing a DLL is actually
hundred times faster than trying to get this to work in LabVIEW).

You need to know that LabVIEW byte arrays are basically a pointer to a
pointer to a buffer with an additional i32 at the beginning indicating
the size. So by allocating a LabVIEW array you can then place a Call
Library Node on the diagram with following configuration:

library: LabVIEW
function name: MoveBlock
return value: void
first parameter: LabVIEW array handle of uInt8
second parameter: uInt32 pointer to value
third parameter: int32 value

Then wire the array to the first parameter, a 0 constant to the second
and a 4 constant to the third. The resulting value from the second
parameter is the pointer to the effective LabVIEW array buffer and
adding 4 to this value will be the pointer to the begin of the actual
array.

Make sure the array wire stays valid until the Call Library Node
returns (by wiring it to a structure boundary which depends on some
output of the Call Library Node and not branching the wire to anyplace
else until that point) and resize the array after the Call Library
Node returns, by the actual size returned somewhere from the Call
Library Node. Make sure the intial array is as large as required by
the API function or as you have indicated in one of the parameters to
the API function as otherwise the function will crash.

Remains filling in the structure which will be a bit of a pain also,
but I told you that writing a wrapper DLL is almost always faster than
trying to do such things in LabVIEW.

Rolf Kalbermatter

Reply via email to