From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW DLL called from C

Solved!
Go to solution

I would like to create a DLL in LabVIEW that can be called from a C program.  

 

The purpose of the DLL is to display a dialog along side a C program user interface and display a picture is updated continuously in the program.  

 

The LabVIEW DLL would

 

1. would be a dialog that open along side the user interface of the C program.

2. the DLL would be called regularly with parameters passed by the C program.

3. the dialog would contains a picture that is updated by the parameters from the C program continously.

 

Is this feasible?  I assume that the DLL has to run as a daemon, since the DLL is a dialog that has to run along side the C user interface.  To run a DLL written in LabVIEW, does the PC needs the run time engine?  

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 11
(2,948 Views)

The general answer to your question is that yes, it can be done. How you do it depends a lot on what you need. There are numerous ways to do this. For example, you could have a VI that launches this dialog as a dynamic VI. This "launcher" VI would be mapped to a function that you'd call from your C code. You'd save the reference to the dialog VI in your LabVIEW code so you could pass it the parameters from C. You'd do this by creating another VI that accepts these parameters and then passes them to the dialog VI. The details on this really depend on what these "parameters" are.

 

As for the Run-Time Engine, yes, you would need to install the Run-Time Engine on the target computer so the LabVIEW code could run.

Message 2 of 11
(2,945 Views)

Let me try to summarize

 

1. create a launcher vi that is compiled into a DLL.

2. The C prgram would called the DLL and activate the launcher vi

3. The launcher vi would launch a dialog vi.

4. The C program would get a reference of the dialog vi from the launcher vi to pass paramters into the dialog vi for continuous update.

 

The test station that runs the C program will need the following:

1. the c program

2. the dll that contains the launcher vi

3. the dialog vi that get launched

4. LabVIEW run time engine

5. LabVIEW development system is not needed

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 3 of 11
(2,941 Views)

No, that's not what I meant. I meant to have everything in the DLL. Remember that when you create a LabVIEW DLL you specify individual VIs as DLL functions (exported VIs). Thus, the launcher and the "set parameters" VIs would be separate functions in the DLL.

 

Of course, as I mentioned there are other ways to skin the cat.

Message 4 of 11
(2,938 Views)

You meant both the launcher and the dialog vi are in the DLL, right?  What did you mean by set parameters vi?  The paramters is passed into the dialog through the C program

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 11
(2,934 Views)

Yes, I was referring to having everything in the DLL. The "set parameters" I mentioned was a way to have a proxy between the C code and the LabVIEW code. The C code wouldn't be able to access the dialog VI directly. It would call this "set parameters" VI with the values it wants to set, and this "set parameters" VI could set the values in the dialog. Since it's inside the DLL it could access the dialog VI.

Message 6 of 11
(2,928 Views)

Why can't I pass the parameter from the c program directly to the dialog vi inside the DLL?

 

If I can't pass parameters directly to the dialog vi inside the DLL, why can I pass parameters to a set parameter vi that is also in the DLL?  

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 7 of 11
(2,911 Views)

Because when you compile the LabVIEW code into a DLL, the C code simply sees functions. The "Dialog" VI becomes a function call. If you call it directly that way, then the C program is going to wait until the function call (i.e., the VI) has finished before continuing to the next line of code. Since the VI is running, it can't do that, so it's not like you can call it again with new parameters.

Message 8 of 11
(2,891 Views)

Does the dialog vi needs to be inside the DLL as well?  Or does it have to be a vi stored somewhere on the PC? 

 

Let me try to summarize again

 

1. create a launcher vi that is compiled into a DLL.

2. create a set parameter vi that is compiled into a DLL.

3. create a dialog vi that is compiled into a DLL

4. The C prgram would call the launcher vi from the DLL.

5. The launcher vi would launch the dialog vi.

6. The C program would get a reference of the dialog vi from the launcher vi and use it to call set parameter vi for continuous update.

 

The test station that runs the C program will need the following:

1. the c program

2. the dll that contains the launcher, set parameters, and dialog vi

3. LabVIEW run time engine

4. LabVIEW development system is not needed

------------------------------------------------------------------
------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 9 of 11
(2,883 Views)
Solution
Accepted by jyang72211

Everything was correct up to 5. For 6 you do not get a reference to anything from C. You just call the exported function that is the "set params" VI.

 

I've included a sample project to give you an idea. The LabVIEW code is written in LV 8.2 and is the project with a build spec for a DLL. I used C# for this example, but you can easily translate it to C if you need to.

Download All
Message 10 of 11
(2,876 Views)