Passing a Struct from a LabWindows/CVI DLL to a TestStand Variable

Updated May 17, 2023

Environment

Software

  • TestStand
  • LabWindows/CVI

Other


 

  • How do I return a struct (e.g. error cluster) from LabWindows™/CVI™ to TestStand?
  • I have CVI DLL with a structure that I am calling in TestStand. TestStand is not accepting CVI code module. I am getting a Run-Time Error: -17311; Could not accept the parameters passed in.
 

In order to return a struct from LabWindows™/CVI™ to TestStand you must do the following:
  1. In LabWindows/CVI create a structure that contains the data you want to pass to TestStand. Here is an example that is used for the rest of the steps:
struct ErrorStruct {
unsigned char errorFlag; // 0 = FALSE, 1 = TRUE
int errorCode;
char errorMessage[256];
};
  1. ​In TestStand, create a custom data type (TestStand Container) that exactly resembles the structure you created in LabWindows/CVI.
  1. Rename the new data type to ErrorStruct (must be the same as the struct in CVI).
  2. Right-click inside the new data type and select Insert Custom Data Type » Boolean to insert a new field in the data type.
    • Rename the new field to errorFlag.
  3. Right-click inside the new data type and select Insert Custom Data Type » Number to insert a new field in the data type.
    • Rename the new field to errorCode.
  4. Right-click inside the new data type and select Insert Custom Data Type » String to insert a new field in the data type.
    • Rename the new field to errorMessage.
  5. Right-click the data type that you have just created in the tree view and select Properties to launch the Type Properties dialog box.
  6. Select the C Struct Passing tab.
  7. Enable the Allow Objects of This Type to be Passed as Structs.
  8. Select errorMessage in the Property dropdown. Make sure that the String Type setting is set to C String buffer.
  9. Make sure the appropriate data types are selected for the other options in the Property dropdown.
    • errorFlag - Signed 16-bit Integer
    • errorCode - 64-bit Real Number (double)
  10. Click OK (saving changes).
  11. Once you have completed this, you can then use the DLL Adapter to call your LabWindows/CVI module that should have a prototype that resembles:
void __declspec(dllexport) Test(struct ErrorStruct *errorCluster); 

Now you should be able to pass data into TestStand from CVI:
//Change the TestStand structure contents
errorCluster->errorCode = 999; 
errorCluster->errorFlag = 1;
strcpy (*ErrorCluster->errorMessage, "Error Occurred"); ​
  1. ​Next, create a local variable in TestStand with ErrorStruct type.
  1. Add a CVI Action into the sequence and configure dll:

Additional Information

Please find the working code (TestStand Sequence and LabWindows/CVI code) used in this tutorial in the attachment.
 

Attachments