LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create a Labview DLL that I can call from c#.net?

I wish to create a LabView Dll and export several functions. I then wish to make use of this dll by making calls from a c# .Net windows App by adding the Labview Dllas a reference.
 
I have created a shared dll and exposed the functions I wish to make use of. I have then added a reference to this dll in my C# project but I am told that the dll may not be a valid .net assembly.
 
has anybody got any thoughts?
 
cheers
 
Steve
0 Kudos
Message 1 of 5
(4,003 Views)
You would do this just like calling any other unmanaged code from C#. Your C# code needs to import the function from your LabVIEW dll using a DllImport attribute.

Assuming your DLL exports a VI called test.vi that accepts a string, then here is how you would import the VI (or rather the exported function from that DLL):

[DllImport ("Test.dll")]
static extern void Test(char[] String);

DllImport requires the following using statement:

using System.Runtime.InteropServices;

Make sure that your DLL is in the search path of your system or in the executable directory, otherwise you will get a System.DllNotFoundException.

You will find more information about calling unmanaged code at MSDN.

Volker
0 Kudos
Message 2 of 5
(3,988 Views)

Hi Volker

Thank you for the reply, my intention was to create an App that could make use of plug-ins.

Thus at present I have an app that will allow me to create plug-ins using c# or vb.net and then make use of the functionality at run time using reflection and late binding.

Having done that I wished to be able create a plug-in using LabView, thus when the dll was placed in the 'relevant' directory my App would detect its presence and allow me to make use of the new functionality.

I should have been clearer , I cannot link to the dll's at compile time as you suggested

whilst LV claims to support .net , to what extent ? Can I produce a .Net assembly using Labview in order to achieve what is described above?

Cheers

 

Steve 

0 Kudos
Message 3 of 5
(3,983 Views)
I am afraid, your plug-in interface can't created directly in LabVIEW. Currently LabVIEW is able to use .NET classes but it is not possible to directly create .NET code using LabVIEW.

My suggestion is to create a C# (or VB) wrapper that serves as glue code for your plug-in interface. On the plug-in side, it implements the interface that is mandated by your plug-in architecture, and on the other side it provides the call into the LabVIEW dll like suggested before. The wrapper would mainly "marshal" the code through into LabVIEW.

This way you would have to drop the wrapper and the LabVIEW dll into that plug-in directory to "install" the code.

I hope that makes sense.
Volker
0 Kudos
Message 4 of 5
(3,971 Views)

Hi Volker

I was sort of expecting that as the answer !

I had sort of come to the conclusion that LV could not create .Net code so thanks for confirming that.

I will look into providing a wrapper as you suggested

thanks once again

Cheers

Steve

0 Kudos
Message 5 of 5
(3,965 Views)