Pointers and Handles in 32-bit TestStand and 64-bit TestStand

TestStand 2019 Help

Edition Date: May 2019

Part Number: 370052AA-01

»View Product Info
Download Help (Windows Only)

TestStand C/C++ DLL Adapter and LabWindows/CVI Adapter steps can support pointers and pointer-sized handles from a single adapter step. For example, 32-bit TestStand and 64-bit TestStand recognize a char * (pointer to character) as a string and a CAObjHandle as a LabWindows/CVI ActiveX Automation Handle. Similarly, a single step can handle functions that take values by reference.

However, if you treat the pointer as a number, a single step cannot simultaneously support the 32-bit case and the 64-bit case. For example, 32-bit TestStand supports treating LabWindows/CVI ActiveX Automation Handles as 32-bit integers, and you can specify the type int instead of CAObjHandle in the C source prototype. You cannot use this strategy for 64-bit TestStand because the int data type is always 32 bits. In this case, for a 64-bit version of the DLL, you would have to replace the int (32-bit) data type with the long long (64-bit) data type, which would change the signature of the function and require a separate step and conditional code to work in 32-bit TestStand and in 64-bit TestStand.

National Instruments recommends using the CAObjHandle data type in C prototypes in conjunction with the TestStand Object Reference data type in the sequence when you pass LabWindows/CVI ActiveX Automation Handles as parameters in adapter steps so the same TestStand step works in the 32-bit case and in the 64-bit case.

Using numbers as pointers when you pass NULL to a function can result in incorrect behavior. In 32-bit TestStand, you can specify the type of a pointer argument as a 32-bit integer in an adapter step and pass 0. Using this technique in 64-bit TestStand results in undefined behavior, such as data corruption or a crash. The code module expects all 64-bits of the pointer to be 0 for NULL, but 64-bit TestStand interprets the argument as only 32-bits, sets only the low order 32-bits, and leaves the high order bits undefined. In this case, to achieve correct results in 64-bit TestStand, you would have to set the type of the number in the prototype to a 64-bit integer and pass 0i64. However, the 64-bit-specific solution would not work in 32-bit TestStand.

To pass NULL as a parameter, specify the data type as a pointer in TestStand and pass Nothing. National Instruments recommends this approach in all cases, regardless of migration or cross-platform support requirements, because TestStand converts Nothing to the correct NULL pointer representation for the current architecture. The Nothing constant is an Object Reference type and is thus a more semantically accurate representation of a NULL pointer than 0 or 0i64.

For C DLLs that do not have associated type libraries or LabWindows/CVI embedded type information, TestStand cannot detect and warn when pointers are incorrectly treated as numbers. One situation in which this issue might arise is when you call Microsoft Win32 API functions in user32.dll or kernel32.dll from the TestStand C/C++ DLL Adapter. National Instruments recommends that when you migrate to 64-bit TestStand, you review all C/C++ DLL and LabWindows/CVI Adapter steps that use these and similar APIs for incorrect use of the number 0 as NULL for pointers.


See Also

Representing Pointers in Sequences in 32-bit TestStand and 64-bit TestStand

WAS THIS ARTICLE HELPFUL?

Not Helpful