LabView 3.1: create DLL in C with Dev-C + + and LabView call

Hello, I am going to write a simple example of an easy way to create discovered DLL (Dynamic Link Libraries) in C and then be able to call in LabView, the example is a pop of "Hello World". More trouble is for me to create a DLL (because the only thing given is compiled directly to machine code libraries fixed), to call a C function in LabView, as this is done easily with the Call Library Function Node VI.

On the National Instruments are three pages of how to make a call, create a C file and build the DLL, I made the first two steps, but the third needed the program Microsft Visual C + + 6.0 that I have, so yet to bring out the steps to do so, I leave the page here in the meantime.

Yet I can let you create rules for your own libraries and run, but I hope you like this example to understand this whole issue of DLL. I guess there are tutorials on how to make DLL with Dev, so do not pretend that this is one, also because I do not read it yet either and so I guess I have trouble compiling my own codes. C headers. H. Def. Can you recommend any other comment on a link to help create DLL in C / C + + easily from any program and then some if LabView explains much better.

  • Step 1: Have installed Dev-C + + and create DLL

The example that I put is version 4.9.9.2, you can see what is available here .

To create a dll file-> name-> Project

Choose DLL, select language in C and put a project name such HelloDll. You must exit the project two files automatically dllmain.cy dll.h. If selected for C + + out these two arichivos but without the example of Hello World.

Archive. C (I have not replaced or the first line):

/ * Replace "dll.h" with the name of your header * /
# Include "dll.h"
# Include <windows.h>
# Include stdio.h
Stdlib.h

DLLImport void HelloWorld ()
{
MessageBox (0, "Hello World from DLL! \ N", "Hi", MB_ICONINFORMATION);
}

APIENTRY BOOL DllMain (HINSTANCE hInst / * Library instance handle. * /,
DWORD reason / * Reason this function is Being called. * /
Reserved LPVOID / * Not used. * /)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;

DLL_PROCESS_DETACH case:
break;

DLL_THREAD_ATTACH case:
break;

case DLL_THREAD_DETACH:
break;
}

/ * Returns TRUE on success, FALSE on failure * /
return TRUE;
}

The. H:

# Ifndef _DLL_H_
# Define _DLL_H_

# If BUILDING_DLL
# Define DLLImport __ declspec (dllexport)
# Else / * Not BUILDING_DLL * /
# Define DLLImport __ declspec (dllimport)
# Endif / * Not BUILDING_DLL * /

DLLImport void HelloWorld (void);

# Endif / * _DLL_H_ * /

That's it, now you do not need to write anything, just go to run-> compile or Ctrl + F9 or the icon color cudraditos above left and we generated the DLL. Maybe he asks you to keep the project. Dev and the generated files. C. H, the DLL will be saved in the same folder or if you indicate your name and project-> project options-> construction you can change them.

  • Step 2: Create the VI

You take a new VI, go to the block diagram, and placed in the Call Library Function Node vi, can be found in conectivity-> libraries & executables. And this, it's that easy, but good for the RUN work better'll put in a structure in the face if True, a button-controlled boolean, and all within a loop Loop that can be controlled also stop with the same button.

  • Step 3: Call Library Function Node Fill

It is given twice a sixth or second button set:

- In the Library Name or Path is set the path to the DLL

- Depending on HelloWorld and it will write it (but it goes badly I think)

- Calling Conventions in C we

- Parameter void that we wrote ourselves (ie not return anything)

- Type void.

And that's it, below is the form of the function void HelloWorld (void); If it were not a function of type VI returning nothing would change the way you can connect inputs or outputs.

It's over-run and luck.

Blogger Post Facebook WordPress Email Share
PDF    Send article in PDF format   

17 Comments to "LabView 3.1: create DLL in C with Dev-C + + and LabView call"

  1. yelinna says:

    Hello
    I do them the Dlls with TurboExploer http://www.turboexplorer.com/ which is free, but weighs 200 megs. You can also do with the free compiler Borland offers (the 5.5).

    Greetings!

  2. cristina says:

    thank you very much! I have been really useful.

  3. Cesar Jimenez says:

    Hello that such!

    I want to connect a canon power shot g9 cmaara and get the image through a window of LabVIEW, apparently I need some dll files for this type of intefaces .... Can you help or give me some tips.

    Cesar Jimenez Calvillo.

  4. weeberp says:

    Hi Caesar.
    The first thing I see is more easily does your camera had to see it as a webcam software or plug can be seen in "My Computer" as webcam?, If so sure you can use the post code Labview Vision 0.5: code simple USB camera
    and the index indicates the name of the camera to be selected.
    If not, no software or not working your USB cable (which certainly connects well) seeks a generic driver that will serve as a webcam, or a program to import photos directly from camera ... I do not know, the case is that if you see video via the PC with it certain that is listed in the list.
    I do not think it easier to find (much less do) a dll that contains a function that calls the image sequence that acts as a video. If you find as you know through the function call node (finding out what kind of data you must call the function or you back, if array, if array pointer, etc ... to define the call).

  5. Uyuni Kenjin Joe says:

    Nice new, like using the library with the same dev with a co lengauje c + +

  6. weeberp says:

    Well, like any library, put # include library (between triangle and quotes based on the location of the file if the default folder or not) and already, call your function in the program.
    Furthermore I have found that putting only the. C in front of the function we want to export, when we define the functions at first, the keyword __ declspec (dllexport) is already public function, then given to the button to create dll program we are utlizando for compilation. This keyword may be slightly different I think from one program to another, but google is fast.

  7. Ray says:

    Hey hey I can do a program builder and use it as you describe in labview 6.1? I have to do a program in labview but I find it more complicated I'm used to always use the C language

    Would greatly appreciate me out of the question!
    Thanks in advance!

  8. weeberp says:

    You can use any program to make DLL, if you know and what you can do. To prove whether I put public functions how I use the little program Dependecy Walker.
    And if in Labview 6.1 can do the same to call a dll, I think it changes the way you do and the place since version 7, but you have the Call Function Node Libray alike. Also avoids the Code Interface Node (CIN), which also serves to execute code, but the fact that however much I read I have not enterder how it works.
    Also remember that you can use C code or language in the same way makes structured node structure, but could not put in here includes or function calls ... And with MathScrpt Node matlab language, but for this I think we need the LabView that includes a full ...
    well here is a manual in English to call external code in labview I 6.0 and 6.1, we use the node as you said before but in a longer, also creating the dll from the beginning ...
    http://www.ni.com/pdf/manuals/370109a.pdf

  9. martin says:

    I could you explain a little better as I can go from c + + language to labview?

  10. weeberp says:

    Pass pass not pass, you can add code is added.
    - If there are functions, or jumps, or anything unusual structures only if .. else .. for ... then Formula Node.
    - If there are functions and a more elaborate program creates a DLL and call it with Call Function Node Libray (the helper Tools »Import» Shared Library (. Dll) comes in handy).
    Code Interface Node do not know how it is used, here's an example: Example of CIN with LabVIEW and MS Visual C + + 5.0 .
    External Code for LabVIEW - CIN / DLL - Starting Point
    - MathScript Node matlab code. My office, you need to have matlab.
    - Want more C? I guess pasate to LabWindows CVI.

  11. federico says:

    hi exite wanted to know if the possibility of other way around, to which I is that if I can get what I do in Labview to C. my question is is that what I do in Labview I can do using it in a micro

  12. weeberp says:

    Now, the question I have I done several times, but what I've gathered so far, following the line of FPGA is that I think NOT.
    To schedule an FPGA if everything LabView program and given to compile a file to convert VHDL or one that accepts the FPGA (as easy as for the NXT), but is only valid for 4 or 5 models and FPGA The module costs a lot of money. I guess for the micro version of ARM ¿? I do not remember will do the same.
    As much as you can get a boolean defined, cluster ... in C. ie if you connect a cluster (for example having more things and complicated) to a Call Library Function Node (first you have to go in and put in the parameters as type Adpat Type) you give to the second button to view the options they have VIs and you hit Create. C File. Well I'm telling you only get the start with a file header. C to fill your entire code.
    As is always the option of LabView CVI, but this is how to program in C (not visual) and is calling labview from libraries to interface buttons subVI.

  13. Fabian says:

    Hello,
    I am newbie in DLL issues, but I wonder if in terms of Matlab MEX files, I have understood are similar to the DLL, I can also use them in LabVIEW. That is, I have a code C q is complex and has been used in Matlab as MEX files, and I use it in LabVIEW. Not if possible or if I should better convert that code to a C DLL with the methods you have proposed.

  14. weeberp says:

    For until now had never read anything about dll files as Matlab MEX called. but looking at NI.com with the keywords "matlab mex" has left me the following:

    * VI ​​to mex using NI LabVIEW Math Interface Toolkit Calling LabVIEW VIs from The MathWorks Inc. MATLAB ® software environment

    * Here I think that makes connection between simulink and LabVIEW NI LabVIEW Simulation Interface Toolkit

    To use the mex in LabView has not left anything so quickly and I never went on reading to connect with LabView libraries, but of course I had never gone otherwise, or from normal autoCAD files ... So if you can compile the C any program and do Dll is a solution.
    *

  15. Fernando_H says:

    Good period thereafter that manages to create the dll to be invoked in labview does not matter which compiler you use, it opens a world of possibilities but also see a world of trouble, especially when what we do is more than "hello world". I have worked hard to use dll's compiled from artificial neurunales networking libraries for use in LabVIEW.
    First problem, data types, when you need the libraries dll passed as parameters complex data types as large structures c + +, the task is a bit distressing to deal a little with these obstacles, create link functions in c + + which can handle data structures c + + and labview make them more edible.
    Second problem, memory management, sometimes, especially when you start programming, you tend to think "if you have compiled is because this well," but if you create a loop in LabVIEW where a function is invoked thousands of times per second , housed in a dll and if that function does not make a proper use of memory you can simply return the system unstable. It is so after being happy to see how the RNA worked perfect, I fell in a few seconds decepcioncuando saw everything and stopped as the computer became slow. I checked all the code c + +, destructors, constructors, so-called new and delete, but found no problems.

  16. weeberp says:

    I agree with you, the truth as it does not get the data to a dll in LabView, if you spend with the size, aiming for something else ... suddenly makes the labview crack and closes suddenly. And slowly clear, at least in 8.6.1.

Leave a Reply

(required)

(required)

CAPTCHA Image
Refresh Image
*