NI Switch Executive

Table of Contents

Using the Configuration API in Visual C++

  • Updated2023-02-21
  • 2 minute(s) read

Include the following lines in your code to use the NI Switch Executive Configuration API from Visual C++:

#include "comdef.h"

#import "C:\windows\system32\nise.dll" tlbid(2) no_namespace

Note Note  The tlbid(2) attribute is important because the COM type library is the second resource in a DLL. The first typelib resource is the NI Switch Executive C API type library for VisualBasic. The no_namespace attribute designates that you can use the NI Switch Executive classes without specifying a namespace.

Example Usage

#include "stdafx.h"

#include "comdef.h"

#import "C:\windows\system32\nise.dll" tlbid(2) no_namespace

int _tmain(int argc, _TCHAR* argv[])

{

HRESULT hr = CoInitialize(NULL);

if (SUCCEEDED(hr))

{

VirtualDevicesPtr nise(__uuidof(NiseVirtualDevices)); // creates a smart pointer, no need to destroy this one

VirtualDevice* vd; // this will hold a pointer to VirtualDevice interface.

long numDevices;

BSTR vdName;

numDevices = nise->GetCount(); // get the number of virtual devices. You should have one (the example one) after default installation

vd = nise->GetItem(1); // get the first element in the collection of virtual devices. You can loop from 1 to numDevices if you want to examine the whole system

vdName = vd->GetName(); //get the name of the first configuration in a collection

SysTreeString(vdName);

vd->Release(); // vd is not a smart pointer, you should release it. Smart pointers end in "Ptr"

CoUninitialize();

}

return 0;

}

Log in to get a better experience