LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I package a Labview as a DLL, and call it from Vis. C++.NET and have the front panel of the VI pop up and act as my GUI?

I have a large piece of code that has already been written in C++ which communicates to tactical military radios via specific protocols through a complicated PCMCIA serial device which can be configured to act like an RS-232 port.

I would like to reuse this C++ code. BUT, I need to change the user interface. What I would LIKE to do is to build the GUI in Labview and package it as a DLL. Then, from my C++, hopefully I can call it and display the front panel on the screen and allow the user to interact with it.

Is this possible?
0 Kudos
Message 1 of 7
(3,710 Views)
Yes you can do this. I recently did this for a project. The first thing you need to do is build the DLL and add your vi as a exported vi. You can also add other vi's and call them using VI server (easy method). Make sure you add them also as exported vi's. Make sure you specify the prototype of the dll and use the function name in your VB call. The second thing that you will need to do is to go into the vi properties menu under window appearance check the boxes "show front panel when called" and "close afterwards if originally closed" in your VI that you want to be the UI. This will then when called load your vi and allow you to use it as a UI. Keep in mind that VB will not be doing anything else while this is going on. VB cannot handle multiple threads
when you call this DLL and will not move on in the program untill the DLL is returned. So make your UI do all functionality that is needed. When running this dll will you have the labview runtime engine installed or will this be running on a computer that has the LV development environment. If it has the LV Dev Environment you will not need to install the runtime engine other wise you will. Also you will be using RS-232, if you are not in the LV Dev. Environment you will need to install the VISA Runtime engine if you are using VISA in the DLL. Finally keep in mind that you must end this vi to return back to VB. A DLL that Hangs is a terrible thing!! Hope this helps.
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
Message 2 of 7
(3,710 Views)
I don't know about what you are asking, but I do the reverse all the time...


I compile the Visual C++ code into a dll, complete with all the IO calls,
then call the visual C++ stuff from labview. Basically, labview is used for
the GUI, and the visual C++ stuff does all the "meat". Is this what you
want to do?


"MFrey" wrote in message news:506500000008000000D99C0000-1042324653000@exchange.ni.com...
> Can I package a Labview as a DLL, and call it from Vis. C++.NET and
> have the front panel of the VI pop up and act as my GUI?
>
> I have a large piece of code that has already been written in C++
> which communicates to tactical military radios via specific protocols
> through a complicated PCMCIA serial device which can be configured to
> act like an R
S-232 port.
>
> I would like to reuse this C++ code. BUT, I need to change the user
> interface. What I would LIKE to do is to build the GUI in Labview and
> package it as a DLL. Then, from my C++, hopefully I can call it and
> display the front panel on the screen and allow the user to interact
> with it.
>
> Is this possible?
Message 3 of 7
(3,710 Views)
Hi BJD1613,

Do your comments on the code stopping while the VI is active also apply if my code is in VC++?

Thanks so much for getting back so quickly,
Mary
0 Kudos
Message 4 of 7
(3,710 Views)
Hi Mike,

Yes, this is what I would like to do, but I'm having problems getting it to work. Right now, my Labview VI makes one call to a function in the DLL, no args, no return value, etc. The DLL is supposed to initialize the serial device, and download a controller file to it. It's telling me it can't load the file.

I've tested the DLL code with an executable C++ file, and the code works fine. Then I thought I would write a small DLL with one function to call CreateFile and open the controller file, then close it. That's it. Well, this is flaky.

The only thing in my LABVIEW VI is a call to the simple DLL function. Sometimes it will open the file, and sometimes it won't.

I'm not sure what else to try to solve this, so I thought I'd switch
it up and approach it from the opposite direction with the C++ code calling the Labview DLL for a GUI.

Incidentally, I tried all of this on LabView 6.1, and I've now loaded 7.0, and I'm going to try it on there and see if the flakiness still exists.... But your answer would be the best solution if I could get it to work.

Thanks for answering so quickly!
Mary
0 Kudos
Message 5 of 7
(3,710 Views)
Mary,
C++ is multi threaded but your code might not be so you must be careful. If it is working as an executable you can call this using the sysexec function in Labview.

Brandon
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
0 Kudos
Message 6 of 7
(3,710 Views)
Hi Brandon,

The original code was running solo in VisC++ and it was an executable. I have been pulling out the functionality I need and packaging it as a DLL. I will try the sysexec as an alternate approach. Thank you for responding.

Best regards,
Mary
0 Kudos
Message 7 of 7
(3,710 Views)