You can pass structures to dlls, but you may have to write a wrapper
function to get the format right.  If the c-code structure does not
match a LV data type, you have to cast it, so-to-speak, in your
wrapper function.  The ability to write such a wrapper function is a
good skill to have.  Read some of the notes previously suggested to
learn how to generate c-code templates for passing various LabVIEW
data types.

To try it for yourself, put a call Library Function node down on your
diagram and right click on it.  Pull down to configure....  Then add a
parameter called myInt32 and make it an int32.  Then add a parameter
called myMatrix and set it to array of double and set it to 2
dimensions, then add a parameter called myStruct and set it to adapt
to type.  Then click OK to get out of the function configuration
dialog.

Put an Int32 control and an array control on your diagram.  Give the
array 2 dimensions.  Put the Int32 and the Array into a build cluster
node.  Now you have three data types on your diagram, an Int32, a 2D
double array, and a cluster of the two.  Wire them to the left side of
your Call Library Function node.  Then right click on the Call Library
Function node and select build .c file.  Voila, you have the prototype
and skelton code for a function that could be used as a wrapper for
your dll.

Follow the instructions for building the dll in the NI literature
making sure to set the path to your original dll for dynamic linking.
Once you have done this, you have created a wrapper dll with functions
that allow you to pass LV types and access the original dll functions
that you want to access.

You should be able to do some simple assignments in the c-code to get
the desired structure ported over to your LabVIEW structure.

You may be able to avoid this code writing exercise provided your dll
contains a function that will give you the pointer.  If it does, you
can store this in a U32 wire on your diagram to access the structure.
The main caveat is that you have to use functions in your dll to
access the structure elements.  Usually, the dll will provide access
to the data in the objects that it creates.

For instance, you might have a structure that contains camera
properties.  The dll usually will have "set" functions like
"setBrightness", "setGain", etc. and complimentary "get" functions.

In your case, you might have a function such as "initStructure" that
will return a pointer to the structure, which has memory allocated by
the c-code.  If so, the U32 number that you get back from this
function is the address, or pointer for the structure, i.e. the
reference location for the structure.  You can then pass this U32
value to any other function called from the dll that requires the
pointer to this structure.

Hopefully, the builder of the dll put in all of the functionality you
need to "set" and "get" the structure elements that you need.  In your
case, you should be able to get the array or an array element and you
should be able to get the int32.  If not, you may have to write some
c-code or perhaps use the low level register access functions.  One of
the advanced LabVIEW folks can tell you whether or not the "peek" and
"poke" or "get" and "put" functions will work across the code
boundaries between the dll and LabVIEW.

Reply via email to