10-30-2008 10:47 AM
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.
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])); //Set address to which should point LV_array
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. }
Solved! Go to Solution.
10-30-2008 10:58 AM
It looks like you're attempting to return the address of 2 defrerences [ $(**... ], have you got a useful error message from a failed build?
10-30-2008 11:13 AM
by changing so:
LStr *LV_array;
LV_array = &(*((**in_array)->Strings));
warning C4047: '=' : 'LStr *' differs in levels of indirection from 'LStrHandle *'
10-30-2008 11:23 AM - edited 10-30-2008 11:31 AM
Have you got the error message from your original attempt?
The pointers and dereferences look like they should be correct in your original post. Is that the line the error occurs in?
EDIT: Actually, I think you might be missing an * before the LV_array->
10-30-2008 11:51 AM - edited 10-30-2008 11:54 AM
LV_array = &(**((**in_array).Strings[*count]));
sprintf(LV_array->str, local_str); - compiles without warnings, but I get error while running VI
sprintf(*LV_array->str, local_str); causes:
>: warning C4047: 'function' : 'char *' differs in levels of indirection from 'uChar'
10-30-2008 11:53 AM - edited 10-30-2008 11:54 AM
Hi,
Try this in that way:

Should be OK.
Complete source in attachment.
best regards,
Andrey.
10-30-2008 12:03 PM
thank you Andrey Dmitriev! spasibo!
With your example I understood where I have error in my code:
I tried to assign to pointer an address of string which wasn't yet pre-allocated!
that means simply swapping strings we get final code:
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. subfunc(count, &in_array); // Call a function which resizes array (works), First we resize array, and only after that we can assign an address of string to a pointer
20. LV_array = &(**((**in_array).Strings[*count])); //Assigning address to which should point LV_array
21.
22. sprintf(LV_array->str, local_str); //passing string to LabView (not working)
23.
24. }