Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
2 ratings:
 3 out of 5   

Calling Functions, in a C/C++ DLL, that have a C Struct as a Parameter from TestStand



Primary Software:
Primary Software Version: 3.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
There is a function in my DLL with a parameter that is a struct. I found the examples in <TestStand>\Examples\StructPassing\LabVIEW that shipped with TestStand, and I could use more direction. How do I set up TestStand to be able to use this function as a code module?

Solution:
There are few actions you will want to take to call the function in the DLL and to pass a reference to the struct you are using. You will want to:
  1. Create a data type to match the struct;

  2. Set the properties of this new type to allow it to be passed as a C Struct;

  3. Create a variable of this new type; and

  4. Use the C/C++ DLL Adapter and insert a step whose code module is the function call.

Here is more on each of the actions mentioned above:

1. Create a data type to match the struct.

To start, create a new data type to mirror your struct. Use the TestStand Container type as an analog to the C Struct. Insert the appropriate fields into the container to match the elements of the struct.

The document linked below provides useful information on completing this action.

2. Set the properties of the new data type to allow it to be passed as a C Struct.

Once the data type is created, you can right-click on the type and select Properties. The Properties dialog includes a C Struct Passing tab. On this tab, you can Allow Objects of This Type to Be Passed as Structs.

Also on this C Struct Passing tab, you will want to select each property of the container and specify the appropriate numeric type. For example, if your struct includes a long, select the Property that matches the long and select Signed 32-bit Integer as the Numeric Type.

3. Create a variable of this new type.

Create a local or global variable of this new data type by right-clicking in the appropriate window and selecting Insert Local»Types»<Your New Data Type>

4. Use the C/C++ DLL Adapter and insert a step whose code module is the function call.

Choose the C/C++ DLL Adapter and insert a step in your sequence. You can right-click on the step and select to specify module. The Edit C/C++ DLL Call dialog will be opened.

Select your DLL and your function. You may be warned that No Parameter Information is available. If so, you will need to simply to press the New button to add parameters to the prototype.

For the struct parameter, select the local or global variable you created in (3) as the Value Expression, C Struct for the Category, and your new data type from (1) as the Type.

Once you have completed these four actions, you have successfully configured TestStand to call the function in your DLL and pass a parameter for the C Struct.

For more details on creating and using a custom data type, refer to Chapter 12 of the TestStand Reference Manual. This chapter includes sections on "Creating and Modifying Custom Data Types" and "Using Data Types".

Related Links:

Attachments:





Report Date: 04/26/2005
Last Updated: 07/01/2014
Document ID: 3KPBEO73

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit