10-12-2010 01:03 PM
Hello,
I am using "Call Library Function" where I call a C function from Labview.
Now .. I want to return an 1 dimensional array from C DLL back to Labview.
Can someone provide an example code how to do it.
When I configure parameter, there are options "Array Data Pointer", "Array Handle" and "Array Handle Pointer".
When I take the first (the simple one), so there is no way labview can know how many items are in the array.
But what is the right to take?
Thanks in advance
Kind Regards
10-12-2010 01:14 PM
@samsik wrote:
Hello,
I am using "Call Library Function" where I call a C function from Labview.
Now .. I want to return an 1 dimensional array from C DLL back to Labview.
Can someone provide an example code how to do it.
Don't need to. An extensive example already ships with LabVIEW. Open the Example Finder (Help -> Find Examples) and search for "DLL". Open the example called "Call DLL".
10-12-2010 02:30 PM
You would run into the same problem calling a function that returns an array in C, because you cannot determine the number of items in an array in C solely from the pointer value that a function returns. Also, it's a bad idea to return an array of unknown size as a function's return value, because that makes the calling function responsible for deallocating the memory even though the called function allocated it. If you don't know in advance how large the array will be, then a better approach is to allocate an array of sufficient size in the calling function (or in LabVIEW, in this case) and pass that by reference to the function, then have the function's return value indicate the number of values in the array that are actually filled with data.