11-03-2008 02:57 AM - edited 11-03-2008 02:58 AM
Hello NI developers!
After solving the problem in http://forums.ni.com/ni/board/message?board.id=170&message.id=365612#M365612 topic. This solution works. What left unsolved - I should assign address to a pointer each time: LV_array = (*((**in_array).Strings[*count])); by this way.
To create a well readable and simple program code I wanted to move a pointer like LV_array++;
Using LV_array = (*((**in_array).Strings[*count])); I assign a pointer to the Strings[*count] element, not to the whole array. So my pointer points to one element, and if I do LV_array++; I get an extra "space" character
in the string indicator.
So I guess I should use something like LV_array = malloc(sizeof(LStr)*(*count+1)) ?
How then to assign reserved pointers to the whole array?
Is is this a good solution: reserving memory for array of pointers to struct and then moving pointer like LV_array++, or assigning each time LV_array = (*((**in_array).Strings[*count])) ?
Thanks in advance.
11-03-2008 05:34 AM
I also wanted to know about the structure from extcode.h :
typedef struct {
int32 cnt; /* number of bytes that follow */
uChar str[1]; /* cnt bytes */
} LStr, *LStrPtr, **LStrHandle;
In what cases I should use each type LStr, *LStrPtr, **LStrHandle ??
11-03-2008 03:57 PM
ACiDuser-
I am not a C Programmer but I am going to try to help out a little bit. What exactly are you trying to use LabVIEW for? (signal conditioning, DAQ, etc.) And what sort of errors are you getting now? There is this website (http://zone.ni.com/devzone/cda/epd/p/id/1288) that provides some really good C help that you might find useful. Thanks!!
11-04-2008 06:41 AM
Hello!
I want to use LabView for DAQ. My DLL works with a PCI-E driver. Inside DLL there are many function, which return messages with a printf(" text info / some stuff here ")
Certainly, If I compile my application as an .EXE, I see those messages in Windows console. If I compile application as .DLL and use LabView as user interface.
I need to use something like Array of String to display those error messages.
The error messages are different:
printf("VIRTEX5_DMAOpen: Failed allocating memory for VIRTEX5 DMA ""struct");
and etc.
By looking at this Array of Strings structures, which is automatically generated by LabView:
typedef struct {
int32 dimSize;
LStrHandle Strings[1];
} LVStringArray;
typedef LVStringArray **LVStrArrayHdl;
we see that Strings element - is an array of elemets with type LStrHandle
Looking in LabView\cintools\extcode.h we find this type defined like this:
typedef struct {
int32 cnt; /* number of bytes that follow */
uChar str[1]; /* cnt bytes */
} LStr, *LStrPtr, **LStrHandle;
LStrHandle seems to be an array of pointers to array of structures (or something else, I might be wrong, cause It's pritty tricky code and a lot of "*" make mess in my head)
So this structures chain looks like this:
LVStrArrayHdl in_array (suppose to be an array of pointers to array of structures of type LVStringArray)
|
LVStringArray (structure)
/ \
int32 dimSize LStrHandle Strings[1] (suppose to be an array of pointers to array of structures of type LStrHandle)
(contains number / \
of Strings in our int32 cnt uChar str[1]
Array) (contains number (is array of type
of characters in unsigned char,
current string) actually it is a string
If in_array is declared in function parameter list like this: _declspec(dllexport) void WhateverFunction( LVStrArrayHdl in_array );
Then to create a pointer to string I do this:
int32 *LV_StrNum = 0 //Set a number of String
LStr *LV_array; //Set a type of pointer.
NumericArrayResize(uPtr, 1L,(UHandle*)&(in_array), (*LV_StrNum)+1 ); //Resizing array
(*in_array)->Strings[*LV_StrNum] = (LStrHandle)(DSNewHandle(sizeof(int32) + StringLen*sizeof(uChar))); //Allocating Handle for current string
LV_array = *((*in_array)->Strings[*LV_StrNum]); //Assign address to a pointer
//Now we can use simply LV_array ->
LV_array->cnt = StringLen; //Set a length of current string
sprintf(LV_array->str, LocalStr); // Write from local buffer to current String
But doing in such way - requires each time increase *LV_StrNum and after that assing pointer again:
++*LV_StrNum;
LV_array = *((*in_array)->Strings[*LV_StrNum]);
Now we are on the next line.
But the problem is - to assign LV_array pointer to Strings[...] so that we
could simply switch on the next line like:
LV_array++;
and then perform:
LV_array->cnt = StringLen;
sprintf(LV_array->str, LocalStr);
I think that I need somehow to allocate memory for *LV_array with help of malloc, but did not reach a working solution yet.
There could be another possible solutions. For example, if it is possible, - running this DLL in LabView with a console in the background, and copy messages
from console to LabView. So that way I could use just ordinary "Printf" function.
But I've spent a lot of time with those arrays and want to solve problem with this pointer.
11-04-2008 08:17 PM - edited 11-04-2008 08:19 PM
Hi ACiDuser,
FYI: In this thread, Wiebe mentions "getting an array of pointers to
string elements in a string array" - not exactly what you requested, but his code may be instructive!
Cheers.
11-07-2008 10:18 AM
ACIDuser-
Were you able to find a solution in tbd's thread? Just checking 🙂
11-10-2008 02:59 AM - edited 11-10-2008 03:02 AM
Hi!
No, but I seemed to solve this problem myself. And this seemed not simplified my code much 🙂
Better would be to make something like this:
LV_array = in_array[i]->Strings[i];
But this doesn't work correctly.