NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create a pointer within a structure?

I have the following C example of what I want to accomplish in TestStand. I am not familar with TestStand, but my customer needs to call my Win32 Dll from his TestStand and is running into issues.

Any ideas?

/*
* SCONFIG Structure
*/
typedef struct
{
unsigned long Parameter; // Name of parameter
unsigned long Value; // Value of the parameter
} SCONFIG;

/*
* SCONFIG_LIST Structure
*/
typedef struct
{
unsigned char NumOfParams; // Number of SCONFIG elements
SCONFIG *ConfigPtr; // Array of SCONFIG
} SCONFIG_LIST;

/*
* Prototype
*/
extern "C" long WINAPI PassThruIoctl( DWORD ChannelID, DWORD IoctlID, void *pInput, void *pOutput );

/*
* Implementation Example
*/
void SetConfig( void )
{
SCONFIG_LIST cfgList;
SCONFIG cfgItems[2];
long lRetVal;

cfgList.ConfigPtr = cfgItems; // Set ptr to point to address of config items array

cfgList.NumOfParams = 2; // Set number of params
cfgItems[0].Parameter = DATA_RATE; // Set 1st config items parameter
cfgItems[0].Value = 10400; // Set 1st config items value
cfgItems[1].Parameter = LOOPBACK; // Set 2nd config items parameter
cfgItems[1].Value = 0; // Set 2nd config items value

lRetVal = PassThruIoctl( 0, SET_CONFIG, &cfgList, NULL )
}

Thanks,
0 Kudos
Message 1 of 8
(4,534 Views)
John -
What version of TestStand are you using?
What are you compiling the DLL with, MSVC or CVI?
What is DATA_RATE and LOOPBACK defined as, because the comment says that it is a "Name of parameter" but the type is an unsigned long?
Scott Richardson
https://testeract.com
0 Kudos
Message 2 of 8
(4,524 Views)
I believe my customer is using 3.1. The DLL is written in Visual C++ 6.0 and is a typical Win32 Dll using an export.def file to expose the functions. The DATA_RATE and LOOPBACK are just constants of type unsigned long. We can see the functions, and call some of them. But this particular function requires the structures defined that use pointers.
0 Kudos
Message 3 of 8
(4,517 Views)

John -
There is a problem that has existed in TestStand 3.x that is fixed in a patch for 3.1. The problem is described as

"Fixed an issue with the C/C++ DLL and LabWindows™/CVI™ adapters when passing a custom data type within a structure which contains a 1-D array of numbers stored as an pointer to array. TestStand 3.1 incorrectly limited the array size to the number of elements specified by the custom data type instead of the number of elements in the instance of the type. TestStand 3.1f1 correctly uses the number of elements in the variable or property that the adapter passes to the code module.

Assuming that you have your C struct packing correct in the TestStand type that you are passing to the DLL, the simple fix to this problem is to make the array size in the type to be the max size that you will ever pass to the function.

The patch is available on NI website at the below link:
TestStand Version 3.1f1 for Windows 2000/NT/XP

I have attached a TestStand 3.1 sequence with the correct struct passing if needed. Sorry for any inconvience that this caused for you and your customer.

Scott Richardson
https://testeract.com
0 Kudos
Message 4 of 8
(4,484 Views)
Thanks for the info on the patch, but what I really need to know is how to create a customer type with pointer as a member. Could you provide a description of how to go about simulating my C description in the previous post.

Thanks,
0 Kudos
Message 5 of 8
(4,481 Views)
John -
Look at the sequence that I previously attached. It has the types that are required to call the DLL function.

In the sequence I first created a "UserDLL_SCONFIG" container type with a Parameter and Value number property. On the C Struct Passing tab for the container I enabled the struct passing and specified "Unsigned 32-bit Integer" for both properties.

I then created a second container type called "UserDLL_SCONFIG_LIST", with a "NumOfParams" number property and a second property called "ConfigPtr" as an "Array of Type 'UserDLL_SCONFIG[0..1]'". On the C Struct Passing tab for this container I enabled the struct passing and specified "Unsigned 8-bit Integer" for the "NumOfParams" property. For the "ConfigPtr" property I specified to store the array as "Pointer To Array" and store the struct as "Embedded Struct".

I then created a Local of type "UserDLL_SCONFIG_LIST" and passed this by reference to the DLL function for the third parameter.

Hope this helps...
Scott Richardson
https://testeract.com
0 Kudos
Message 6 of 8
(4,478 Views)
OK, maybe I'm blind!! Where do you find attachments to posts?

Thanks,
0 Kudos
Message 7 of 8
(4,464 Views)
John -
Not sure why it did not post with my note, I will try it again.
Scott Richardson
https://testeract.com
0 Kudos
Message 8 of 8
(4,435 Views)