Programming with the TestStand API in Microsoft Visual C++

TestStand 2019 Help

Edition Date: May 2019

Part Number: 370052AA-01

»View Product Info
Download Help (Windows Only)

Using #import

You can use the #import compiler directive to automatically generate C++ classes for Microsoft Visual Studio to access the objects defined in TestStand type libraries.

To generate C++ classes for TestStand, you must first add the <TestStand>\Bin directory to the list of additional include directories in the Visual C++ project settings.

TestStand adds TestStand API directories to the list of include directories that Microsoft Visual Studio uses to locate files.

In Visual Studio 2010 or later, enable the Enable TestStand Include Directories option on the NI TestStand property page of the Project Properties dialog box for a C++ project to specify whether to use TestStand include directories.

After you update the include directories, add the following directive at the top of the source file:

#import "teapi.dll"

When compiling this directive, Visual C++ generates teapi.tlh and teapi.tli in a Debug or Release directory that contains the intermediate files for the project. The generated files contain definitions of C++ classes that correspond to the TestStand API classes. Each C++ class contains methods for each of the corresponding TestStand API methods and properties.

By default, Visual C++ encloses the TestStand-generated classes within a TS namespace to avoid possible conflicts with other C++ identifiers that have the same names. As a result, when using the generated classes, you must prefix each class name with TS::, as in TS::Sequence. To avoid the need to prefix the class names with the namespace, you can add the no_namespace attribute to the import directive. You can also add a using namespace TS statement after the import directive, as shown in the following examples:

#import "teapi.dll" no_namespace


#import "teapi.dll"

using namespace TS;

In addition to teapi.dll, you can import the following files:

  • TsAdpApi.tlb—Import this type library file to access the TestStand Adapters API. The default namespace for the TestStand Adapters API is TSAdp.
  • tsui.dll and tsuisupp.dll—Import these DLLs to access the TestStand User Interface (UI) Controls API. The default namespace for tsui.dll is TSUI and the default namespace for tsuisupp.dll is TSUISUPP.

The tsapivc.h and tsapivc.cpp files import the type libraries for the TestStand API, TestStand Adapters API, and TestStand UI Controls API.

If you plan to use the TestStand API in many different source files, you might want to add the #import directive to the precompiled header file. Use tsapivc.h and tsapivc.cpp to more easily use the TestStand API in many different files. These files are located in the <TestStand>\API\VC directory. To use these files, include tsapivc.h in the precompiled header and include tsapivc.cpp in a single source file in the project so you can access the TestStand API C++ classes in all of the source files that use the precompiled header.

Using Microsoft Foundation Classes (MFC) Wrappers

TestStand does not install MFC wrappers for accessing the TestStand API. If you have source code that uses the tsapimfc.cpp and tsapimfc.h files from a previous version of TestStand, complete one of the following actions when you upgrade TestStand:

  • Convert the code that uses MFC wrappers to use the Microsoft Visual Studio #import wrappers instead. Use the tsapivc.cpp and tsapivc.h files to access the TestStand API using these wrappers.
  • Use Visual Studio to generate MFC wrappers for TestStand.
  • Continue to use the wrappers provided by a previous version of TestStand.


Not Helpful