NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I pass an array of structs to a C function using the dll flexible prototype adapter?

What I want to do is pass into a C dll function a variably sized Array of structs of type TPS_Data. My Code compiles but when I run it in TestStand, I get an error -17001; Program Error. "Cannot allocate 0 size buffer Error in parameter 2, 'OpenFrdData'."

I've allocated the Array of structs, and all of the information is there before I call my function, so is it my prototype? Or am I asking too much of the DLL Flexible Prototype Adapter to pass an Array of Structs?

I can pass in a single struct of type TPS_Data and that works, but not an array.

Here's the relevent code:

typedef struct TPS_DATA
{
char Report_Number[256];
char System_Name[256];

char Open_Date[256];
char UUT_Part_Number[256];
char UUT_Serial_Number[256];
char UUT_Name[256];
char Open_Employee_Name[256];
char Open_Employee_Number[256];
char Close_Employee_Name[256];
char Close_Employee_Number[256];
char Close_Date[256];
} TPS_Data;

typedef struct TPS_DATA_ARRAY
{
TPS_Data DataRecord;
} TPS_DataArray;

long __declspec(dllexport) __stdcall OpenDialog (CAObjHandle Context, TPS_DataArray *TpsData[], const char *psFaultStr, char *sComments, const int nCount);
0 Kudos
Message 1 of 17
(5,844 Views)
OK,

I can pass the data to the DLL function, using the following types:

typedef struct StringArrayType
{
char string[10][256];
} StringArray;

typedef struct MultiStringArrayType
{
StringArray Record[10];
} MultiStringArray;
void __declspec(dllexport) __stdcall ATP_TestStructPassing(StringArray Strings)
{
return;
}

void __declspec(dllexport) __stdcall ATP_TestMultiStructPassing(MultiStringArray *Strings)
{
return;
}

But when the MultiStruct function Exits, TestStand reports an Error:
-17501 "Unexpected Operating System Error" Source: 'TSAPI'

There doesn't seem to be a way around this, and once the error occurs, I have to force quit TestStand. I've included the sequence file, and the dll code can be compiled from the fun
ctions shown above.

Any thoughts on how to get around this error would be greatly appreciated.
0 Kudos
Message 2 of 17
(5,841 Views)
Unfortunately, you can't pass a variably-sized array of structs with the DLL Adapter.

The only kind of array the adapter lets you pass is an array of numbers, although you can get around this limit by passing a custom data type that contains a member that is an array of structs.

It looks like you tried this, but the problem is that the size of the array still isn't variable - it must be the same as the size of the array in your custom data type. In your first post you probably got the "0 size buffer" error because you set the array to be initially empty.

In your second post it looks like you tried something a little unusual - you defined the custom data types to be arrays themselves instead of containers with array members. Theoretically it should work, but it look
s like you uncovered a bug in TestStand. It will work if you replace those custom data types with containers that have array members. But keep in mind that the array size is still fixed.
0 Kudos
Message 3 of 17
(5,842 Views)
You were correct about our getting the "0 size buffer" error. However, I'm not clear on the concept of creating an array within a container - I tried this with my example and using various pointer & value combinations still did not get me what I wanted. The best I could do was see the first element if the StringArray struct in the container (the rest was garbage). Can you take my example that I sent in and show me what you mean in the sequence file?
0 Kudos
Message 4 of 17
(5,842 Views)
By container with array member, I mean creating a custom data type that is a container and adding a property to it that is an array. See MultiStringArray2 in the attached file.
0 Kudos
Message 5 of 17
(5,842 Views)
One teensy little problem with your example - For some reason, TestStand v2.0 thinks it's saved as a TestStand v3.0 Sequence and gets errors when I try to open it. Can you redo it as v2.0?

Thanks for helping and getting back so quickly, it is Greatly appreciated!
0 Kudos
Message 6 of 17
(5,842 Views)
Sorry about that. Here is the correct file.
0 Kudos
Message 7 of 17
(5,843 Views)
Hi,
I'm trying to do something somewhat similiar. I want to pass an array of C struct (in my case Labview's TelnetScript struct.). If I understand correctly this is impossible to do in TestStand 3.1? The array length can be fixed or variable, of course I would prefer it to be variable ;-).

Thanks!

Louis
0 Kudos
Message 8 of 17
(5,751 Views)
Louis,

From what I can tell, passing an array of C structs is possible in TestStand 3.1, and yes, the array needs to be fixed length. You’ll want to create two custom data types – one to match the struct and then an array of that type. On the struct type, be sure to allow it to be passed as a C Struct in the Properties.

Also, if the struct you mentioned is being passed to/from a LabVIEW VI, then it is actually a cluster. If this is the case, you’ll want to allow the custom data type you make to be passed as a LabVIEW cluster. This can be done in the properties of the type.

Regards,

Eric M
0 Kudos
Message 9 of 17
(5,728 Views)
All right so first I want to let you know that I am using TestStand and passing the struct array to a LabWindows DLL. So from what I understand I can do the following: create my 2 data types, one being the struct and the 2nd being an array of that struct. When I declare a variable of the array type of length 1024, I see an list of 1024 structs. Done. But now when it comes to Labwindows, how is this data type declared? Do I simply declare an array of the struct or do I have to declare a new datatype, and if so how should it be done?

So far I've been able to pass my array of struct by placing it inside a container in TestStand and declaring a new struct corresponding to that container in Labwindows like this:

typedef struct TelnetScriptArray {
TelnetScript TelnetScr[1024];
} TelnetScriptArray;

Where TelnetScript is my original structure.

Thanks for the information!

Louis Girard
0 Kudos
Message 10 of 17
(5,721 Views)