Showing results for 
Search instead for 
Did you mean: 

How can I create only one instance of Vi in project?


I am creating GUI for Lab view User. My application is already created in Qt and C++. I am trying to use same code  for Lab view GUI.

Stand alone application is start by creating the object of 



 from the Main Function.
Here the Code of main function for stand alone application.


int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    MainWindow w;
    return a.exec();


Now I am creating GUI for Lab view user. It will be look like below.
whenever the Other developer are use at that time they need to


  1. Select Device ( list of connected device).
  2. Select Channel (w.r.t device selected in Select device, Some device has 4 channel or some Device has 1 Channel).
  3. Configure the Button (verify the device channel is busy or not)
  4.  Select the Custom Experiment, give folder Path to save data, and Start Experiment.


 To achieve above functionalities in lab view I am planning to create few API in C wrapper.  API Will be like below.

1)	Mainwindow* StartApplication();
           create object of Mainwindow for the application
           start The Serial Communication thread through constructor of the MainObject.
           return pointer of object of Mainwidnow.
2)	void CloseApplication();
           destroyed object of Mainwindow.
           stop the Serial Communication thread through destructor of the MainObject.
           Cleanup the other memory through destructor of the Mainwindow.
           set the pointer to NULL pointer.
3)	Char*[] getListOfDevice()
           Listing connected device through method of MainObject Class.
           Return devices names, which are connected to the PC.
4)	Int getNumberOfChannle()
            return the Number of Channel w.r.t Selected Device in Combo Box.
5)	bool getStatus()
            verify selected device and Channel are busy or not.
                   if Channel is busy then return false.
                   if Channel is not busy then return  true. 


StartApplication(); and CloseApplication();

are help to start/close the application, and I am planing to create subVi (name : for this two API. 


1) How can I create only one instance of in whole project? (like singleton design pattern in C++).


I would like to call 

StartApplication() and CloseApplication();

API only single time.

I would like to achieve below functionality. 
      -- when user first time use at that time  should call before calling (Call StartApplication() API).

      -- If user second time use  in same application then I do not want to call the CFL node of but I wanted to just read the pointer of instance of MainWindow. (I think I will add another pointer holder in

     -- if user delete all the from the his Application at that time should call and delete the Mainwindow instance. (call CloseApplication()). 

if it is any efficient way to achieve same functionality then happy to accept advise.

0 Kudos
Message 1 of 7

Perhaps the best way to do this would be to use LabWindows/CVI instead of LabVIEW? Making C wrappers to interact with LabVIEW is going to be a long, difficult road.


Why can't you just write the functionality in LabVIEW itself? Handling Windows is entirely doable in LabVIEW. I'd recommend doing the whole thing in LabVIEW if possible. Whatever must be left to C can be left to C calls, which can be called within LabVIEW. The window creation/destruction stuff doesn't need to be done in C at all (unless there's some other reason you haven't told us).


LabVIEW is a programming language all by itself; it's not just a window/button handler.

Message 2 of 7

If you're familiar with C++, you can create an API function (basic IPC using namedpipes for example. Where your API has the namedpipe client side code and the labview code, when called from also instantiates a c++ dll which can have the server side pipe host.). Easiest way then would be to send a sample command to the port. If it fails (this means the server side code on the isnt up), it means  can be launched. If your command gets through, it means the service is up and you don't have to launch the again. 

This might take a bit of experimentation but I have implemented this pattern back in my days as a .net dev. I might take a look at this if I get time maybe. This is what i mean: sample.png

PS: I'd suggest that you handle the entire polling or process handling within labview and just use the api interface for communication. That would also mean a proper use of Separation of Concerns.  

Message 3 of 7

Thank you BertMcMahan for advise. I am trying to use dll because of two reason.

1) My application is already created in C++ code, and In future if I need to make change in code then I require to make change in code at one only place instead of both code, Labview code, and C++ code.

2)  I do not require to implement all functionalities (functionalities are contain by our Software) in Labview Gui. I wanted to just send the few Command to instruments through lab view GUI. 


I wanted to just select the Device, Select the Channel,Selected location of Experiment File, Start/Stop Experiment in lab view. Then reaming stuff will do by our software code.

Do think still I need to go with only Labview code??

Thank you



0 Kudos
Message 4 of 7

Your first post has a lot of window handling in it- those functions will be quite annoying to implement in LabVIEW. If you want to do instrument comms with your DLL's that should be fine, but you don't want to do your window handling in C++.


I'd go with making single functions that can be called from within LabVIEW if they're already written, just don't try to do any window handling in C++. Just handle the button presses, menu selections, etc. in LabVIEW then call the correct DLL for that specific sub-function.

Message 5 of 7

Thank you newbieprogrammer  for direction. I understand your approach. Let me try with IPC.


Thank you,


0 Kudos
Message 6 of 7

Do let me know how that goes! 🙂 

0 Kudos
Message 7 of 7