LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using LStrPrintf to print only limited subset

Hello,

 

I am a bit strugling using LStrPrintf inside DLL.

 

I am passing a 2D string array, everything works OK, but when I try to access individual elements using LStrPrintf to copy the data from array string handles, I allways copy some garbage, because the handle has no null termination for its data. I tried to limit the copied data using standard printf arguments, but it has some limited functionality.

 

 

typedef struct {
	int32_t dimSize1;
	int32_t dimSize2;
	LStrHandle Strings[1];
} LVStringArray2D, **LVStrArrayHdl2D;

//THIS WORKS and returns 0
int StrArrAllocPokus2D(LVStrArrayHdl2D StrArr, LStrHandle LVStringH, int32_t element)
{
	return(int)LStrPrintf(LVStringH, (CStr)"%.1s", (*(*StrArr)->Strings[element])->str);
}

//THIS crashes on LStrPrintf (no return)
int StrArrAllocPokus2D(LVStrArrayHdl2D StrArr, LStrHandle LVStringH, int32_t element)
{
	return(int)LStrPrintf(LVStringH, (CStr)"%.*s", 1, (*(*StrArr)->Strings[element])->str);
}

 

0 Kudos
Message 1 of 3
(2,182 Views)

Hello,

 

I want to be clear about your problem: with the function written below "//THIS WORKS", you get no error and you succesfully copy one character from StrArr 2D string array to LVStringH,right? And when you use this: 

 

int StrArrAllocPokus2D(LVStrArrayHdl2D StrArr, LStrHandle LVStringH, int32_t element)
{
	return(int)LStrPrintf(LVStringH, (CStr) (*(*StrArr)->Strings[element])->str);
}

you read nonvalid data? What is configuration of parameters in Call Library Function Node for these functions?

 

Some usefull links to this: http://zone.ni.com/reference/en-XX/help/371361J-01/lvexcode/printf/

and the overview of strings formats in attachment. 

 

Best regards,
Pavel J.
0 Kudos
Message 2 of 3
(2,142 Views)

Thanks, thats a nice usefull link.

 

I used a workaround and convert the handle to Cstring first, after that I have no problem with garbage.

 

CStr buf = (CStr)calloc(sizeof(uChar), (*LVStringH)->cnt + 1);
uint32_t err = LToCStrN((*LVStringH),buf,(*LVStringH)->cnt);

 

 

 

0 Kudos
Message 3 of 3
(2,113 Views)