LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multidimensional string array dispose & reinitialize in DLL

Hi,

I need to pass a multidimensional string array to DLL, dispose the content of the string array, resize the string array, fill it and return it to LabVIEW. I pass the string array to DLL as adapt to type. The first problem seems to be that I cannot get the content of the old string array disposed. How should one releas memory to an array of strings. I assume that each string handle must be released separately in order to avoid memory leaks.

In addition I cannot get the string array resized and filled. How should one resize a string array in a DLL.  For some reason the array is not filled either but I haven't debugged that far yet because of the previous problems.

I want to use the same function for string arrays of various dimensionality, that's why I dont't have struct typedef telling exact form of the string array struct below. I'm using Win XP, LV 8.0.1 & Visua Studio .NET 7.1.

A stripped down version of my function as well as a block diagram and call library function configuration are attached.


--
Tomi Maila
0 Kudos
Message 1 of 2
(2,788 Views)
I managed to find the solution to emptying a string array by myself. The C function to do this is below.

#include "extcode.h"

/* DisposeLStrArray_LStrHandles dispoes all the LabVIEW string handles
   in a LabVIEW string array of any dimensionality.

   int 32 rank              - the dimensionality of the LabVIEW string array
   UHandle str_array_handle - handle to the LabVIEW string array
   LVBoolean * resizeToZero - if LVTRUE, the string array is resized to 0, otherwise
                              the size is left as it was and all the string handles
                              in the array are disposed
*/
MgErr EmptyLStrArray(int32 rank, UHandle str_array_handle, LVBoolean * resizeToZero)
{       
            MgErr err=noErr;
            int32 Initial_points=1;
            int32 * Initial_dimsizes = (int32*) *str_array_handle;
            for (int i=0; i<rank; i++)
                Initial_points*=Initial_dimsizes[i];
           

            for (int i=0; i<Initial_points; i++)
            {
                LStrHandle * temp_handle = ((LStrHandle*) (*str_array_handle+sizeof(int32)*rank))+i;
                err=DSDisposeHandle(*temp_handle);
                if (err) return err;
                *temp_handle=NULL;
            }
            if (*resizeToZero == LVTRUE)
            {
                Initial_dimsizes = (int32*) *str_array_handle;
                for (int i=0; i<rank; i++)
                       Initial_dimsizes[i]=0;
                err=DSSetHandleSize(str_array_handle, rank*sizeof(int32)+sizeof(LStrHandle));
                if (err) return err;
            }

            return err;
}

--
Tomi Maila
0 Kudos
Message 2 of 2
(2,783 Views)