From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

build dll with array output

Solved!
Go to solution

Hi, I'm new to building dlls or interfacing Labview VIs with other programming languages. This is my first attempt trying to build dlls, so I have a basic question. Can anyone can point to how I can build a dll in Labview to return an array or array pointer?

For example, I have no problems producing a function prototype: double functioname (double arg1, double arg2, ...) using the application builder drop down menu under Source Files. But once I have an array output, arrayOut, in the VI, arrayOut is not available as a return value in the drop down menu. Only single value doubles are available as return values.

I seem to be able add the arrayOut as an argument pointer, but I am having problems calling back such a prototype in matlab.

 

Thanks.

 

FA

0 Kudos
Message 1 of 6
(3,724 Views)
Solution
Accepted by topic author farn

Hi farn,

 

In order to pass an array in or out of a Labview DLL function you must pass an array data pointer along with the length of the initialized array to the VI in the function call.  When defining the VI Prototype while creating the DLL, Labview will automatically create an array pointer and its associated length value as 2 of the parameters if an array configured to be output on the wiring block of the VI.  The array will need to be instantiated to a certain length in the program calling the DLL.  The pointer to this array and its predetermined length must then be passed in to the DLL.  After execution the array data will be accessible at that memory location.  Also here's a little example I found that might be of some use to you.  http://zone.ni.com/devzone/cda/epd/p/id/1518

Justin D
Applications Engineer
National Instruments
http://www.ni.com/support/
Message 2 of 6
(3,702 Views)

LabVIEW does not support array pointers as function return values. Reason is that there is no way to inform the caller about how big that array actually is. Another issue is about who will be responsible for deallocating the array pointer. So in order to pass an array from a DLL to LabVIEW you have to use function parameters. And the caller needs to allocate the array buffer, and also pass the size of the allocated buffer in a seperate parameter to the function.

This is a limitation in LabVIEW but one heavily dictated by how C usually deals with data. C has never defined a standard in how to pass variable sized data (or pointer data) around other than the pointer format itself. LabVIEW as a managed application (to use a ,Net term) needs very specific memory pointer conventions. For it's own native data types it has a well defined behaviour and for other data it dictates a very specific regime.

Rolf Kalbermatter
My Blog
Message 3 of 6
(3,693 Views)

Thanks, JustinD, rolfk,

 

Got it to work! The simple example helped a lot. I thought I did try previously to specify the array and array length as function parameters but the caller just crashed. Maybe I used the wrong numbers; works great now. But I do get the main idea that arrays as outputs have to be specified somehow in the function parameters and cannot simply be used as return values.

 

A separate, minor question: why doesn’t the labview dll builder include extcode.h as part of the build folder or put the absolute path of the extcode.h in the header file? Currently, it simply writes #include extcode.h. I have to edit it manually every time I build a dll. Minor issue, though it would be nice if the builder can include all the header files necessary to run the dll.

 

Thanks anyway!

 

FA

0 Kudos
Message 4 of 6
(3,682 Views)

Hey farn,

 

In the DLL creation wizard there is an option under Advanced to "Include additional LabVIEW Header Files".  This option will include all the header files in the build directory.  However, I am not sure why it references the header file by default as if it is in the local directory.

Justin D
Applications Engineer
National Instruments
http://www.ni.com/support/
0 Kudos
Message 5 of 6
(3,677 Views)
Ahh...should read the options more carefully. Thanks.
0 Kudos
Message 6 of 6
(3,669 Views)