10-08-2008 04:44 AM
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.
Solved! Go to Solution.
10-08-2008 04:58 AM
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.
10-08-2008 05:16 AM - edited 10-08-2008 05:17 AM
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"
10-08-2008 05:36 AM
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!!
10-08-2008 06:17 AM
10-08-2008 06:54 AM