LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Executing Call Library Node inside the DLL

Solved!
Go to solution

You forgot to use count+1 in the relevant places as you did correctly in the previous example. And it would be better to use NumericArrayResize instea of DSSetHandleSize due to platform alignment differences which NumericArrayResize will take care of but DSSetHandleSize won't.

 

LStrHandle is equal to a pointer and that is an uInt32 for all current platforms and uInt64 for the upcoming LabVIEw for Windows 64Bit version. You could define a new type in your header like:

 

#if ProcessorType == kX64
 #define uPtr uQ
#else
 #define uPtr uL
#endif

 

If you have included the extcode.h from LabVIEW you should now be able to use uPtr as first parameter to NumericArrayResize() to actually allocate the right amount of memory buffer even if you ever are going to recompile that code for LabVIEW for Widows 64 Bit.

 

Rolf Kalbermatter 

Message Edited by rolfk on 10-27-2008 08:21 PM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 11 of 17
(1,419 Views)

Hello, thank you. I modified source code and now it works, but when I pass to LabView a string via "sprintf" function, It doesn't type after the first space " " sign. Why this happens?

And also, allocating space for string -writes garbage data, I use ClearMem function to remove this stuff. Is it a correct way to do?

0 Kudos
Message 12 of 17
(1,409 Views)
Solution
Accepted by topic author ACiDuser
In the attachment there are source files with detailed description
Download All
0 Kudos
Message 13 of 17
(1,408 Views)
setting StringLen  to 60, solves problem, but It's still unclear about such strange behavior.
0 Kudos
Message 14 of 17
(1,398 Views)

It most likely doesn't stop. But LabVIEW strings are not zero char terminated but their length is instead only determined by the len parameter inside the structure. So what is most likely happening is that LabVIEW sees a string returned like "some text\0\0\0\0\0\0\0\0\0\0\0\0\0\"

where the \0 are NUL characters. Now if you display that in a single line string control LabVIEWs automatic strong control line wrapping kicks in and since the many NUL characters are to long to fit into the line LabVIEW line breaks at the  previous space character displaying the rest on the second (invisible) line. After filling in information into a LabVIEW array (and a string is really just an array too) you do have to update the len (or DimSize, which is in fact the same) to tell LabVIEW how many array elements (characters) are really there. In fact for LabVIEW arrays you shouldn't seperate the allocation of the handle and the filling in in most cases since you either allocate why to much in most cases or you will sooner or later end up filling more into a handle than you have previously allocated for it, causing those nasty crashes again.

 

Rolf Kalbermatter 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 15 of 17
(1,373 Views)
  1. typedef struct {
  2.         int32   cnt;            /* number of bytes that follow */
  3.         uChar   str[1];         /* cnt bytes */
  4. } LStr, *LStrPtr, **LStrHandle;
  5.  
  6. typedef struct {
  7.         int32 dimSize;
  8.         LStrHandle Strings[1];
  9. } LVStringArray;
  10.  
  11. typedef LVStringArray **LVStrArrayHdl;
  12.  
  13. _declspec(dllexport) void avg_hello(int *count, LVStrArrayHdl in_array)
  14.         {
  15.  
  16.         unsigned char *local_str="Entering function ma_in()";
  17.         (*count) = 0;
  18.         LStr* LV_array;
  19.  
  20.         LV_array = &(**((**in_array).Strings[*count]));
  21.         subfunc(count, &in_array); // Call a function which resizes array (works)
  22.         sprintf(LV_array->str, local_str); //passing string to LabView (not working)
  23.  
  24. }
LStr, *LStrPtr, **LStrHandle structure is taken from LabView cintools extcode.h
 
   I used: sprintf(((*(*in_array)->Strings[*count])->str), local_str); to pass local_str string to
LabView array.  It worked fine, but  one programmer adviced me to change code to  be more readable.
Means - to change  (*(*in_array)->Strings[*count]) construction to a pointer. I tried many different
ways to implement this - but in all cases it caused LabView to crash. I understand that this question
is related to C programming not about LabView, but could you point me at a place where I have mistake ?
The most likely incorrect string is " LV_array = &(**((**in_array).Strings[*count])); "
 
Thanks in advance.
 
Message Edited by ACiDuser on 10-30-2008 07:56 AM
Message Edited by ACiDuser on 10-30-2008 07:58 AM
0 Kudos
Message 16 of 17
(1,354 Views)
I found the error, thanks
0 Kudos
Message 17 of 17
(1,320 Views)