NI Home
Cart Cart | Help
Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Currently Being Moderated

Using Existing C Code or a DLL in LabVIEW

VERSION 6

Created on: May 12, 2008 1:55 PM by Kevin_S - Last Modified:  May 19, 2009 11:23 AM by Natasa Lingurovska

 

This tutorial explains how to convert existing C code to a DLL (Dynamically Linked Library) and then how to call that DLL from LabVIEW.  If you already have a DLL, start on step 10.  (Note: This tutorial explains how to create a DLL that can only be used in LabVIEW.  If you want to create a DLL out of your C code that will then be downloaded to the FIRST cRIO controller, see this article.)

 

1. Use an integrated development environment capable of creating DLLs. (This tutorial uses Microsoft Visual Studio 2005.)

 

2. Create a new project.

 

3. Create a C++ Win32 Console Application. Specify a Name. Specify a Location.

 

4. Click Next for more options.

 

5. Select DLL from Application type.

 

6. Add your function to the default program. (See my function in bold.)

int Multiply( int a, int b )

{

return a*b;

}

 

 

7. Add the following prototype to the default program. (See my prototype in bold.)

extern "C" __declspec(dllexport)int Multiply( int a, int b );

 

 

8. Build the DLL.

 

9. Note where your DLL was created.

 

10. Open LabVIEW and place a Call Library Function Node on the Block Diagram.

 

11. Double click on the Node and specify the DLL to load and the function to access.

 

12. Under the Parameters tab, specify the Return Type (the data being passed back from the function) and press Add a parameter in order to specify each of your input parameters.

 

13. Right click on each of the 3 outputs and create an indicator. (Note: You have the option of viewing as outputs each of the input parameters to the DLL.)

 

 

 

 

 

14. Right click on each of the 2 inputs and create controls.

 

 

 

 

 

 

 

 

 

15. Go to the Front Panel. Specify values for the 2 controls (the input parameters).

 

16. Run the VI in order to execute the DLL.

REQUIREMENTS:
Application Software: Academic MultiMCU 9.0.34
Driver Software: NI ELVIS Software 3.0.1
Hardware Family: 5B
Add-on Software: LabVIEW Application Builder 7.1
Product Category: LabVIEW
Development Topic: Instrument Drivers - Learn
Industry: ATE/Instrumentation
Application Type: Simulation
Technology: Bluetooth
Average User Rating
(0 ratings)




RobSteele RobSteele  says:

Will this same method work with something like bloodshed's (http://www.bloodshed.net/) C or C++ compiler. I've used that compiler in the past and it has worked very well - and it is free.

Kevin_S Kevin_S  says:

Hi Rob,

There are many different Integrated Development Environments (IDE) that can create DLLs capable of being called from LabVIEW.  I would recommend trying it out with your specific environment.  Just know that if you are using an IDE like Microsoft Visual Studio 2003 or newer, be sure to create a C DLL (an unmanaged DLL) and not a .NET DLL (a managed DLL).

 

Regards,

Kevin S.

Applications Engineer

National Instruments

RobSteele RobSteele  says:

I got the C portion to work under Visual Studio and Bloodshed's compilers. I could not get the C++ classes visible through the DLL to LabView. Is this possible to do - and if so how would I do it?

Kevin_S Kevin_S  says in response to RobSteele:

Hi Rob,

 

If you could, please submit this question under Discussions (instead of as a comment to this tutorial) so that multiple people can view, respond to, and search for your question.

 

Kevin S.

Applications Engineer

National Instruments

More Like This

  • Retrieving data ...

More by Kevin_S