LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String from DLL to LabView within two odd characters

Solved!
Go to solution

   Hello. I pass a string from DLL to Labview, and the result indicates correct, but there is two odd characters everytime "Gn"

 

 

 If the character I pass is " a ", then the result is "a Gn".

 

My DLL code is:

 

  void massiv_int(char *lv_ptr);

_declspec(dllexport) void f_massiv(char hello[]);

_declspec(dllexport) void f_massiv(char hello[]) {


 char lv_str[10];
 char *lv_ptr;
 lv_ptr = &lv_str[0];

 massiv_int(lv_ptr);
  * hello = lv_str[1];


}

void massiv_int(char *lv_ptr) {


 char lv_local[10] = "abcdefg";
 memcpy(lv_ptr, lv_local, 10);
}

 

 Could you tell me, what might be incorrect?

Thanks in advance. 

 

 

0 Kudos
Message 1 of 6
(3,318 Views)

Hi there

 

simply change the code to

 


void f_massiv(char hello[]) {


 //char lv_str[10];
 //char *lv_ptr;
 //lv_ptr = &lv_str[0];

 

 massiv_int(hello);

 

 //massiv_int(lv_ptr);
 //*hello = lv_str[1];
}

 

The original line  "* hello = lv_str[1];" just sets the FIRST character in the character string "hello" to the first character in the character string "lv_str", which is 'a'. The rest of the characters in "hello" stay uninitialized, so they contain garbage.

 

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 2 of 6
(3,310 Views)

Thank you very much, now it works.

 

 

 But what to do If I want to go to next line?

 

 

I mean output should be like:

  ______________

 | abcdef                |

 | qwerty                | 

 |_______________| 

 

 

 void massiv_int(char *hello);

_declspec(dllexport) void f_massiv(char hello[]);

_declspec(dllexport) void f_massiv(char hello[]) {

 massiv_int(hello);


}

void massiv_int(char *hello) {

 char lv_local[10] = "abcdefg";
 memcpy(hello, lv_local, 10);
}
 

 then massiv_int() calls another function which contain string "qwerty"

 

 

 

Message Edited by ACiDuser on 10-08-2008 05:17 AM
Message Edited by ACiDuser on 10-08-2008 05:17 AM
0 Kudos
Message 3 of 6
(3,302 Views)
Solution
Accepted by topic author ACiDuser

Try this:

 

void massiv_int(char *lv_ptr);
void massiv_int_NextLine(char *lv_ptr);


LVSTR_API void f_massiv(char hello[]) {


 //char lv_str[10];
 //char *lv_ptr;
 //lv_ptr = &lv_str[0];

 massiv_int(hello);

 //massiv_int(lv_ptr);
 //*hello = lv_str[1];
}

void massiv_int(char *lv_ptr) {

 // make lv_local as long as needed (no extra characters)
 char lv_local[] = "abcdefg";

 // copy all characters in lv_local to lv_ptr
 strcpy(lv_ptr, lv_local);

 // add next line
 massiv_int_NextLine(lv_ptr + strlen(lv_ptr));
}


void massiv_int_NextLine(char *lv_ptr){

 // make lv_local as long as needed (no extra characters, including LF)
 char lv_local[] = "\nqwerty";

 //  copy all characters in lv_local to lv_ptr
 strcpy(lv_ptr, lv_local);

}

 

 But make sure the external string buffer allocated by LV is long enough to hold all characters!!

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 4 of 6
(3,293 Views)
Thank you! 🙂 it works perfect
0 Kudos
Message 5 of 6
(3,279 Views)
// DLL for LabView
//
// “lv_read( )” function passes two row string to LabView
//

// declaration of two sub-functions 
void func1(char *lv_str); 
void func2(char *lv_str);

_declspec(dllexport) void lv_read(char lv_str[]);

_declspec(dllexport) void lv_read(char lv_str[]) {

 func1(lv_str);
}
void func1(char *lv_str) {

// make array_local as long as needed (no extra characters)
 char array_local[] = "abcdefg";

// copy all characters in array_local to lv_str
 strcpy(lv_str, array_local);

// add next line
 func2(lv_str + strlen(lv_str));//“+ strlen(lv_str)” moves pointer to the end of existing string
}

void func2(char *lv_str){

// make lv_local as long as needed (no extra characters, including LF)
 char array_local[] = "\nqwerty"; // “\n” throws to the next line

// copy all characters in array_local to lv_str
 strcpy(lv_str, array_local);

}


0 Kudos
Message 6 of 6
(3,274 Views)