02-01-2006 01:32 AM
Daijoubu is indeed right about his findings. One other approach to solve this problem would be to declare your variable static.
@nmxnmx wrote:
Thanks you very much for your explanation daijoubu, and yes It's for sure I will read the links you gave me... Thanks very much again![]()
02-01-2006 05:24 PM
02-02-2006 05:41 AM
In your example lstring is not really a LabVIEW string in terms of datatype but a C string instead. As such it is very important that you preallocate the memory in LabVIEW for your C function to write into the string. If you wire up a LabVIEW control to the CLN and configure the datatype as C string it will only pass a pointer to the data contained in the LabVIEW string control. If the string control contains an empty string you will basically pass a pointer to a one byte memory area to the DLL. Any function trying to write data into that string will write past the end of that one byte buffer and overwrite data that might and usually is vital to LabVIEW. LabVIEW might immediately display a Protection Fault dialog, crash after the call to the function, crash later on maybe only when you try to close it, or just corrupt your VI when saving it to disk.
@nmxnmx wrote:
Thanks too rolfk, and well as you know a function such as :
char *test_string()
{
static char string_data[MAXDATA]; /*MAXDATA previously defined*/
strcpy(string_data, "string_test");
return string_data;
}
it was just a test to do the real function, so now I will thing the best is do it like:
char *test_string(char *lstring)
{
/* Code of function */
one_funtion_that_use_string(lstring);
return lstring;
}
where lstring is a LabView String coming from a LabView String control, and the return value is goin to be placed in a LabView String indicator.
02-03-2006 10:42 AM