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.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use .dll created in LabVIew with string array output using LStrHandleArray

I have a .dll made in LabVIEW that I want to use in CVI.  I have been able to use the rest of the functions without problem, but there is one that returns an array of ints and an array of strings.  I have access to the LabVIEW source code so there is potential to attack this from either end but first I'd prefer to just learn how to use this datatype.  Below is my header file with just the one function I'm concerned with along with the autogenerated functions and typedefs.

 

#include "extcode.h"
#pragma pack(push)
#pragma pack(1)

#ifdef __cplusplus
extern "C" {
#endif
typedef uint16_t  Mask_Type;
#define Mask_Type_SetMaskOff 0
#define Mask_Type_SetMaskOn 1
#define Mask_Type_SetMaskAll 2
typedef struct {
	int32_t dimSize;
	LStrHandle SerialNumber[1];
} LStrHandleArrayBase;
typedef LStrHandleArrayBase **LStrHandleArray;

/*!
* rb_GetDeviceInfo
*/ uint32_t __cdecl rb_GetDeviceInfo(uint32_t devices, uint32_t deviceIdx[], LStrHandleArray *deviceSerial); /* * Memory Allocation/Resize/Deallocation APIs for type 'LStrHandleArray' */ LStrHandleArray __cdecl AllocateLStrHandleArray (int32 elmtCount); MgErr __cdecl ResizeLStrHandleArray (LStrHandleArray *hdlPtr, int32 elmtCount); MgErr __cdecl DeAllocateLStrHandleArray (LStrHandleArray *hdlPtr); #ifdef __cplusplus } // extern "C" #endif #pragma pack(pop)

 

You might as well say I'm clueless as to how to allocate and use the LStrHandleArray type in the function. From my other functions, I  know in my C code how many devices there are ahead of time so I used the AllocateLStrHandleArray function with the number of devices and then passed it into rb_GetDeviceInfo function (below is a partial snippet of this part).

 

ftStatus = rb_GetNumDevices(&numDevices);
	
uint32_t deviceIdx[numDevices];
LStrHandleArray deviceSerialNumber = AllocateLStrHandleArray(numDevices);
ftStatus = rb_GetDeviceInfo(numDevices,deviceIdx,&deviceSerialNumber);

 

The function runs succesfully and I get the deviceIdx values back but the deviceSerialNumber remains the same as it was before the function ran.

 

I'm not sure how to allocate and use this data type so if anyone can explain it to me I'd appreciate it.  The other possibility would be to change the LabVIEW code so that it was a different type - basically this would be a char** if everything was written in C.  Is there anyway I can convert it to be a char** in my .dll?  A solution for either of these would work fine for me.

 

Thanks for the help in advance.

0 Kudos
Message 1 of 3
(4,848 Views)
0 Kudos
Message 2 of 3
(4,843 Views)

I still couldn't figure out exactly how to use to use the LabVIEW types to get it working in the original way I had postd, but the thread you directed me to helped me to get around i but going that route.  I just made it so there is a max number of devices (the limit being imposed by the number of elements in the LabVIEW cluster.  I'm not a huge fan of arbitrarily limiting the number of devices, but I also can't forsee using more than 8 anytime in the near future so this should suffice.  Thank you for the help.

0 Kudos
Message 3 of 3
(4,763 Views)