LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I insert a C file into my DLL?

I know how to write a simple C code for use in a DLL : I put it  between the brackets after I use "creat .c file" in the "Call Library Function Node".I did it and the DLL did fine. But what do I do when I want to put inside a big program that includes 5  source files (.c)  and one header file (.h)?
0 Kudos
Message 1 of 6
(3,366 Views)
Hi Dror,

The Code Interface Node (CIN) allows you to create the shell of a function to pass and manipulate LabVIEW datatype data in a text based language.  A function created using this method could be linked to other functions as well, which you would do within the text based files.

If you have a complete application, you can also call an executable using the System Exec VI. 

See the document Using External Code in LabVIEW, and the LabVIEW Help section: Calling Code Written in Text-Based Programming Languages
Doug M
Applications Engineer
National Instruments
For those unfamiliar with NBC's The Office, my icon is NOT a picture of me 🙂
Message 2 of 6
(3,340 Views)


@Dror wrote:
I know how to write a simple C code for use in a DLL : I put it  between the brackets after I use "creat .c file" in the "Call Library Function Node".I did it and the DLL did fine. But what do I do when I want to put inside a big program that includes 5  source files (.c)  and one header file (.h)?


You create a DLL project and use the prefered method of your compiler system to define which functions the DLL should export. How this is done is very much dependant on your compiler and IDE and you should refer to its online documentation to understand how that is done.

Note: The other recommendation to use CINs is absolutely no time saver nor future proof. CINs are legacy technology and are likely to get less and less support from NI with future versions of LabVIEW.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 3 of 6
(3,334 Views)
Thank you for your answer,
I would like to focus on DLL because I already know how to use it. The question is  when I get this situation:
* Call Library Source File */

#include "extcode.h"

long avg_num(float a[], long size, float *avg);

long avg_num(float a[], long size, float *avg)

{

/* Insert Code Here */

}

Now I am supposed to replace the /* Insert Code Here */ spacer with the  function code, placing the code within the pair of curly braces.

But what if my code is a very long program consisting on several files and  a header. Can I simply use include?

0 Kudos
Message 4 of 6
(3,284 Views)
Thanks rolfk, I'll stick to the DLL.
0 Kudos
Message 5 of 6
(3,281 Views)


@Dror wrote:
Thank you for your answer,
I would like to focus on DLL because I already know how to use it. The question is  when I get this situation:
* Call Library Source File */

#include "extcode.h"

long avg_num(float a[], long size, float *avg);

long avg_num(float a[], long size, float *avg)

{

/* Insert Code Here */

}

Now I am supposed to replace the /* Insert Code Here */ spacer with the  function code, placing the code within the pair of curly braces.

But what if my code is a very long program consisting on several files and  a header. Can I simply use include?



You should really study a text book about developing in C. Every IDE for just about every modern C compiler has a concept called project. In there you add all de C source files that are needed to create your DLL, EXE or whatever. Almost every DLL or EXE nowadays consists of numerous C source files that implement specifc groups of functions and each of those can simple call functions that are implemented in one of the other C source files or even in a precompiled object or library file. The project manager compiles all C source files into object modules and then the linker adds them all together to the final executable image.

If you work on the command line things get a little more difficult as you have to compile each C source file yourself and at the end also start the linker to link everything together. But this is usually made simpler by writing a make file that does this all for you and using automake systems or similar do the most difficult work for you too.

Rolf Kalbermatter




Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 6 of 6
(3,265 Views)