LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How would I write a shared library in CVI and call it in LabVIEW?

Solved!
Go to solution

I have recently been asked to assist other developers that are using LabVIEW.  The trouble is that I use LabWindows/CVI or VB.NET. 

 

In order to launch, I would like to know how I could make the simplest library possible:

 

1. Call DLL in LabVIEW

2. DLL outputs a string "Hello World!"

 

This is two steps.  I need to make the program in CVI with a function to return a string holding the value "Hello World!", and I need to have a colleague call that function in LabVIEW.  Let's focus on the CVI side step 1 since this is the CVI forum. 

 

How can I do this?

 

Note: My current experience with CVI is writing a program with no UI for real time PXI targets.

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 1 of 11
(2,726 Views)

It's not particularly hard, and it's been discussed before: https://forums.ni.com/t5/LabWindows-CVI/Create-dll-for-use-in-Labview/td-p/3226349

 

0 Kudos
Message 2 of 11
(2,696 Views)

That link has two links to the CVI help site and neither go to their original sources.  They just go to the top.

 

The forum post says you need to put your code into a "Function Panel."  I don't know what a function panel is.  Because my only experience with CVI is writing for real time targets, I always have a main function and some program flow with no UI.  For a dll to add functionality to LabVIEW, is it only a set of functions without main, or do I still need main?  I also have to have a .h file.  What would this .h file hold?  Currently my .c file holds everythign wrt the real time application.

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 3 of 11
(2,646 Views)

I have opened an example in CVI.  If I don't need a GUI would I just remove the panel parts of the example like I do for other sample code I import for real time targets?

 

 

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 4 of 11
(2,641 Views)

You can start by examining the examples of DLL projects that ship with CVI.

Start the Example Finder by executing Help >> Find examples... menu item, next open Search tab and search for "DLL": this will list in the middle section of the window all the examples related to DLLs that are present on your disk. Click on each of them to read a short description in the Information box. Double-click on an example to open it in the CVI IDE. I suggest you to start from cvidll.prj example.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 11
(2,634 Views)

I am trying cvidll.

 

I tried to run it and it said I needed to go to Run->Specify Executable and Command Line.  It doesn't really tell me what it's looking for here, so I tried to Google it.  No good examples.

 

So here is what I tried:

DieselPower_0-1702321408867.png

 

Still not happy:

DieselPower_1-1702321435407.png

 

 

DieselPower_2-1702321474179.png

 

 

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 6 of 11
(2,617 Views)
Solution
Accepted by DieselPower

This is the readme file in the project:

These samples require you to do the following:

1. Generate the LabWindows/CVI DLL and Import Library using cvidll.prj
2. Add the generated Import Library to the usecvidll.prj project
3. Run the usecvidll.prj project.

It works for me (CVI2017) and it does not ask for anything!

 

As you can see, the example consists of two projects: Cvidll.prj and Usecvidll.prj; both are listed in the workspace tree.

 

You should:

  • Right-click on Cvidll project and select Set active project
  • Build the project as-is: it will create the dll and import library
  • Right-click on Usecvidll project and select Set active project
  • Execute Edit>> Add Files to Project >> Library (*.lib)... menu function: browse and select the created .lib file to add it to the project: it will be listed under Library Files section
  • Run the project


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 7 of 11
(2,602 Views)

OK that worked.  I was pressing the play button when I should have just built it.  I followed your instructions and it worked perfectly.

 

Thank you!

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 8 of 11
(2,588 Views)

The saga continues...

 

I opened LabVIEW and ran the Import Shared Library Wizard.

 

DieselPower_0-1702476568260.png

Didn't add any include paths.

DieselPower_1-1702476585587.png

It finds the functions.

DieselPower_2-1702476605388.png

DieselPower_3-1702476624324.png

DieselPower_4-1702476699674.png

 

Seems OK so far:

DieselPower_5-1702476736386.png

 

DieselPower_6-1702476755391.png

Errors!?!

DieselPower_7-1702476768696.png

 

Your generated files are installed in the following folder:
C:\Program Files (x86)\National Instruments\LabVIEW 2018\user.lib\cvidll

Parsing header file warnings:
No errors/warnings occurred when parsing the header file.

The following errors/warnings occurred when generating the wrapper VIs for this shared library.

VI Not Executable
The VI is not executable because of one of the following reasons:
1. The shared library or a dependent file is not installed. To make the VI executable, you must install the shared library and all support files on the computer on which you run the VI.
2. A required custom control might be empty or cannot be found. To make the VI executable, update the custom control manually.
3. The VI contains a parameter with an unsupported data type. To make the VI executable, you must replace the empty cluster that the wizard generates with a control or indicator that uses supported data types.
    DLL Func1.vi
    DLL Func2.vi

 

Trying to drop it in the block diagram of LabVIEW.

DieselPower_0-1702476870875.png

 

 

Any ideas?

 

 

 

 

 

 

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 9 of 11
(2,564 Views)

OK.  Disregard all of that.  I found a youtube link where some kind gentleman has dumbed it down for me.  He made a library with a single function.  Following his instructions, though they were actually to call the dll from CVI, I got it to work easily in LV using the same process from the prior post.  That means the DLL doesn't really need to have a special format (main, etc.).  It ONLY needs to have the functions required in it.

 

https://www.youtube.com/watch?v=RqgEdenkBRs

 

DieselPower_0-1702486334648.png

 

 

DieselPower_1-1702486360815.png

 

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 10 of 11
(2,552 Views)