Switch Hardware and Software

cancel
Showing results for 
Search instead for 
Did you mean: 

NISE Configuration API for C++

Hi,
is it possible to use NISE Configuration API in C++
I think all need is just a Wrapper-Class
or .tbl
 
greetings form
the Lake Of Contstance
 
Juergen
 
 
 
--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 1 of 7
(7,898 Views)
Greetings, Juergen!

Bodensee is a beautiful place indeed!

In MSVC++ you can use the #import directive to include the type library of the COM component you'd like to use. The type library for NISE is embedded in the nise.dll, so you can point to the install location of nise.dll to get it. I think that you can also use the ProgID, for more location-independent application. See #import documentation on MSDN for more information.


Here is the code that uses NISE COM API in C++; you can plug it in as is, in a console app, and it works. The vdName ends up being “SwitchExecutiveExample” after clean installation.

A couple of important points:

tlbid(2)  attribute is important, because the COM type library is the second resource in a DLL; the first typelib resource is the NISE C API type library for VisualBasic.
no_namespace means that you can use the smart pointers without specifying namespace.

#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

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

      CoUninitialize();
   }
    return 0;
}

-Serge
Message 2 of 7
(7,889 Views)

Hello Srdan,

You are absolutley right the region Bodensee is a really nice place.

But now don´t lets talk about this place.

Thank you very much for your help information. I thought it might could

be done with #import. Like if you know, with the TestStand API.

But I never, never! found tlbid(2) attribute. So thanks again.

Greetings

Juergen, 

 Hm! You saved a lot of time for me, so I should go to lake

and drink a "Weizenbier" for you.

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 3 of 7
(7,875 Views)
Hello Srdan,
I have two  addtional questions.
 
1) Have you ever tried this under VC6
For me it seems to be impossible because the attribute "tlbid" is
not supported under VC6. 
This is a feature is available since VC7
Why the old VC6?
because i have lot of classes that are writen and (tested!!) under VC6
Is there a way to import?
 
2) Under VC7 your Console-App is running.
but if you do this in a DLL-Function
and call this from a TestStand-Step, the step crashes at :
vdName = vd->GetName(); //get the name of the first configuration in a collection
Do you know why
 
If you do this with C# (Win-App)
everything is working fineSmiley Very Happy
 
 
greetings from
the Lake of Constance
Juergen
 
--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 4 of 7
(7,838 Views)
Hi Juergen,

For msvc6, what you need to do is open nise.dll as a resource in msvc6, go to type library resources, right-click on the "2" and choose "Export" option. Pick a file name, e.g. niseCfg.tlb, and store the file somewhere on your system where you will use it in the #import statement:
#import "somePath\niseCfg.tlb"

I'll look into the other issue, it may be related to the CoInitialize, you may want to look into CoInitializeEx and play with it. But I'm not sure...

Best regards

-Serge
0 Kudos
Message 5 of 7
(7,836 Views)

Juergen -
I tried calling calling the COM API using TestStand ActiveX/COM steps and they worked fine from a regular TestStand Execution thread that uses multithreading by default.

This is not a recommended solution, but if this is a threading model issue, one option to try is to force a TestStand thread to use a single threaded apartment when executing your steps. To do this add your steps that will access the NISE API to a separate sequence. Add a Sequence Call step to invoke that sequence. Specify to run the sequence in a separate thread and specify that to use single threaded apartment. Make sure that you set to wait on the thread.

The next step after the above would be for you to possibly share your project and code for someone to look at.

Scott Richardson
National Instruments
0 Kudos
Message 6 of 7
(7,828 Views)

Hi

I want to use NISE to handle switches.

 

I want to make a C/C++ application.

I want to receive a path with a NISE Configuration file and see that file to make the connection.

 

I don't know what functions can i use to get the routes from the VirtualDevice that i import with niseCfg_Import

 

CAn anyone help me?

 

Thanks

0 Kudos
Message 7 of 7
(6,747 Views)