LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Do I need to call DeAllocateLStrHandleArray?

Posted this in the LabVIEW forum and was told this forum could be a better place, so copying pasting here.

 

Compiled a VI as a DLL. One of the outputs is an array of LabVIEW strings. Interface defines the call as:

int32_t __cdecl function(..., LStrHandleArray *X, ...);

and gives me three managing functions

LStrHandleArray __cdecl AllocateLStrHandleArray (int32 elmtCount);
MgErr __cdecl ResizeLStrHandleArray (LStrHandleArray *hdlPtr, int32 elmtCount);
MgErr __cdecl DeAllocateLStrHandleArray (LStrHandleArray *hdlPtr);

 I allocate a LStrHandArray to pass to my function and call the function as

  LStrHandleArray X = AllocateLStrHandleArray(0);
  MgErr error = function(..., &X, ...);

Everything works fine.  Do I need to call?

MgErr error DeAllocateLStrHandleArray (&X);

If I do it returns an error (18438).  Not too worried about not calling it, as the code exits a couple of lines below, but just wondering what it is and how to convert that to an error message.

0 Kudos
Message 1 of 6
(3,215 Views)

Hi! 

Do you have more information about that error (18438)?

 

 

this is a good link a found about LStrHandArray:https://stackoverflow.com/questions/40406105/using-lstrhandlearray-in-net

 

0 Kudos
Message 2 of 6
(3,171 Views)

@Andr3s_Br3n3sDo you have more information about that error (18438)?

No idea where to look this up.  There is a function in extcode.h, called NIGetOneErrorCode but I don't think that will work, as the enum listed in the header doesn't cover that range.

 

this is a good link a found about LStrHandArray:https://stackoverflow.com/questions/40406105/using-lstrhandlearray-in-net


That is kind of a tutorial on how to call the DLL, but I've done that already.  And it uses DSNewHandle()/DSNewHClr() , when I'm trying to use the supplied allocation functions provided by LV when I compile the DLL and that I posted in my initial post.

0 Kudos
Message 3 of 6
(3,166 Views)

Hi instrumento,

 

Do you have the font code of the dll?

If you call this dll in LabVIEW or in any other environment are you having this error (18438)?

Did you wire all the errors wires on LabVIEW?

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

The source code of the DLL is a LabVIEW VI. 

The DLL is built by one of the build targets of a LabVIEW .lvproj. 

When LabVIEW builds the DLL it generates a .h header file with the Allocate, Resize and DeAllocate LStrHandleArray that I posted, and then use from a simple Win32 console application.

 

There is not a lot of documentation on this.

Allocate returns  a LStrHandleArray, assuming failure results  in a NULL.

Resize and DeAllocate return MgErr, which I assumed to be error codes.

 

I changed my VI a bit and the error code from DeAllocate is tied to the size of the returned strings, and not always 18438.

If I return a random number N of the same 6 character string back, the returned value is N*17+8, always.

If I return  a random number N of random length strings, I couldn't quickly come up with a formula for the returned value, but it seems to be tied to the number of strings and the length of all allocated strings.

 

I'm starting to believe that DeAllocate either returns the number of freed bytes (or is telling me that it is leaking those bytes).

 

 

0 Kudos
Message 5 of 6
(3,139 Views)

Ok, seems interesting!

I don't have an answer for that right now, but let me double check some information.

 

 

 

 

 

 

0 Kudos
Message 6 of 6
(3,129 Views)