LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove the "int len" of my return string on the DLLS header when building a DLL on LabVIEW 8.5

Hi all.
I'm building a DLL on LabVIEW and I choose a string as an output on the terminals connectors.
But LabVIEW creates another output, the lenght of the return string.
This is a problem because I have other DLLs and I need them to be compatible.
How do I remove this length from the header? What is the difference between Pascal String and C string and String Handle Pointer?
String Handle Pointer removes the length from the header but I don't know the difference between this data types.
Thanks in advance for the help.
 
Daniel Coelho
Portugal
 
Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
0 Kudos
Message 1 of 4
(2,942 Views)


@Daniel Coelho wrote:
Hi all.
I'm building a DLL on LabVIEW and I choose a string as an output on the terminals connectors.
But LabVIEW creates another output, the lenght of the return string.
This is a problem because I have other DLLs and I need them to be compatible.
How do I remove this length from the header? What is the difference between Pascal String and C string and String Handle Pointer?
String Handle Pointer removes the length from the header but I don't know the difference between this data types.
Thanks in advance for the help.
 
Daniel Coelho
Portugal
 


C string pointer is a pointer to a memory location whose string information is terminated by a 0 byte. Pascal String Pointer is a pointer to a memory location where the first byte specifies the number of bytes to follow. This obviously allows only for strings up to 255 character length.

LabVIEW String Handle is a pointer to a pointer to a memory location where the first 4 bytes are an int32 value indicating the number of characters to follow. You can read such a String handle in a function without many problems, but you can only create, resize and delete such a handle by using LabVIEW memory manager functions. So this makes only sense if the caller of such a DLL is LabVIEW too as another caller would have to go through several hoops and tricks in order to gain access to the correct LabVIEW kernel that could provide the memory manager functions to deal with such handles.

Last but not least output strings whose allocated length is not passed to the funciton as additional parameter are a huge secerity risk (talk about buffer overrun errors). LabVIEW DLL Builder does not support the creation of DLLs with output string (or array parameters)  without the explicit passing of an additional parameter telling the DLL function how large the allocated size is (so that the DLL function can make sure to never write over the end of the buffer).

The additional length parameter only disappears for String Handles because LabVIEW will simply resize them to whatever length is necessary and that is also the reason why those handles need to be allocated by the same memory manager instance that is also going to execute the DLL function.

Resizing of memory pointers is non-standardized and in normal circumstances not suited for passed function parameters at all.
 
Rolf Kalbermatter


Message Edited by rolfk on 06-13-2008 12:28 PM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 4
(2,937 Views)

Thank you for the very good the explanation.

I wasn't aware of those types of error. I'll change my other DLLs in order to return an extra argument, the string buffer length.

Thank you for your quick reply.

My best regards,

 

Daniel Coelho

Portugal

 

Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
0 Kudos
Message 3 of 4
(2,931 Views)


@Daniel Coelho wrote:

Thank you for the very good the explanation.

I wasn't aware of those types of error. I'll change my other DLLs in order to return an extra argument, the string buffer length.

Thank you for your quick reply.

My best regards,



It's not so much for returning the length of the actual returned string (strlen() can tell you that too) as much more for the DLL function to make sure to not write past the end. So it is in the first place an input parameter (passing by value would be fine for that) but you can of course use it also to return the number of actually filled in string characters (in which case you need to make it passed by reference).

So your non-LabVIEW DLL functions will in fact use functions like strncpy() instead of strcpy() to avoid the possibility of buffer overruns.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 4
(2,926 Views)