How to Store Size_t Data in TestStand Variables

Updated Oct 18, 2024

Reported In

Software

  • TestStand

Issue Details

I have a DLL that utilizes a size_t datatype variable. I want to be able to pass the data to both 32-bit and 64-bit TestStand, modify the data, then pass it back to my DLL. However, it appears the 32-bit version of TestStand recognizes size_t data as a float and the 64-bit version recognizes the data as an unsigned 64-bit integer. How can I create a variable in TestStand that can handle the size_t datatype without having to change the numeric representation of all of my TestStand variables?

Solution

The size_t datatype does not have a direct equivalent in TestStand. Therefore, you cannot pass out a value from a function in a DLL and store it directly into a numeric variable in TestStand without setting the representation of the variable to Double Precision 64-bit Floating-Point in 32-bit TestStand or Unsigned 64-bit Integer in 64-bit TestStand.

Instead, you can define the function in your DLL to pass a pointer to your variable but still return the actual value of the variable. In TestStand, you can then set the Return Value type from your function to Pointer/Handle and store the variable in an Object Reference Variable. The screenshot below highlights where to define these settings in the parameters of your DLL in TestStand.



You can then retrieve the value of that Object Reference variable by inputting the expression below into an expression step. Note: This code will work on both 32-bit and 64-bit TestStand if Locals.Int64Number is a Signed 64-bit Integer, however only the low order 32-bits of the integer will be used on 32-bit TestStand.

Locals.Int64Number = (&Locals.objectRefVariable).AsPropertyObject.GetValInteger64("", PropOption_Coerce)

The value of your size_t data will then be stored in Locals.Int64Number and can be used as a regular 64-bit signed integer.

Similarly, if you want to modify the value of 
Locals.Int64Number then pass it back to the DLL, you can use the following statement to convert the signed 64-bit integer back into an objectRefVariable.

(&Locals.objectRefVariable).AsPropertyObject.SetValInteger64("", PropOption_Coerce, Locals.Int64Number)

Once you have the new value stored in Locals.objectRefVariable, you can pass it back into the DLL by calling a function that requires a size_t pointer as an input. In TestStand, you will then have to select the parameter you are passing into the DLL, click on the Category field drop-down menu and select Pointer/Handle as the value. You will also have to click the drop-down menu for the Pass field and select By Value as the value. The screenshot below highlights where to define these settings in the parameters of your DLL in TestStand.


 

Additional Information

An example sequence file and DLL's for both 32-bit and 64-bit TestStand are included in the zip file in the Attachments section of this article to further demonstrate the solution outlined above. You can open the sequence file in 32-bit or 64-bit TestStand. To run it, you only have to select the DLL with the corresponding version bitness of the TestStand version that you are working in and adjust the parameter calling options as described above.

Attachments