07-16-2021 12:40 PM
I have a third party .net dll that I am having trouble implementing. There is one class in the dll and I am able to access its methods by using invoke nodes, but the dll also has an interface. I need to create a class that uses this interface and then pass a reference to this new class to one of the other methods.
If I pass a reference to the interface it throws an error because it is null, I need to create a class that inherits this dll interface and then pass a reference to it.
How can this be done in labview 2018? I am having trouble figuring out where to start from browsing topics online and I would appreciate some help. Thanks
Solved! Go to Solution.
07-16-2021 01:17 PM
@JDPRI wrote:
I have a third party .net dll that I am having trouble implementing. There is one class in the dll and I am able to access its methods by using invoke nodes, but the dll also has an interface. I need to create a class that uses this interface and then pass a reference to this new class to one of the other methods.
If I pass a reference to the interface it throws an error because it is null, I need to create a class that inherits this dll interface and then pass a reference to it.
How can this be done in labview 2018? I am having trouble figuring out where to start from browsing topics online and I would appreciate some help. Thanks
AFAIK, you'll can't use LabVIEW. LabVIEW can't implement interfaces. I hope I'm wrong...
You'd need to use a .NET (C#, F#, Visual Basic .NET, C++ CLI, etc.) compiler.
You don't need to install anything to build an assembly though. .NET has a build in C# compiler!
It can compile exe and dll files. I haven't tried an interface though.
07-16-2021 02:28 PM
Thanks for the reply. Just to make sure I am understanding right, I can write the class in C# that inherits the interface from the third party dll file, and then use this labview compiler to generate the dll for it, then I can add the new dll as the reference I need in my original project. Is that right?
07-16-2021 02:41 PM
@JDPRI wrote:
Thanks for the reply. Just to make sure I am understanding right, I can write the class in C# that inherits the interface from the third party dll file, and then use this labview compiler to generate the dll for it, then I can add the new dll as the reference I need in my original project. Is that right?
Sounds right.
Nothing special about this solution: it basically means use C#, not LabVIEW. Except it avoids installing Visual Studio.
There are options: make a LabVIEW assembly and use it in the C# dll. Make a C# and use it in LabVIEW.
I don't actually know how the C# dll can communicate with LabVIEW either way.
07-17-2021 08:07 AM - edited 07-17-2021 08:41 AM
As mentioned by Wiebe you can not let LabVIEW generate .Net classes that inherit from another .Net class or implement a specific .Net interface. When you turn a LabVIEW class into a .Net assembly it always directly inherits from the .Net Object class only.
So you can’t implement “callback” classes in LabVIEW that you can pass to a .Net API. If your .Net API doesn’t support .Net events as an alternative, you’ll have to create a .Net intermediate assembly in C# (or whatever your preferred .Net language is) that implements this “callback” interface and translates it into something you can work with in LabVIEW. This could be a .Net event in your helper class, or invoking PostLVUserEvent() on a user event refnum passed to your helper class constructor from LabVIEW.
Maybe you could make a product suggestion to the 3rd party assembly provider to add .Net events to its class implementation if they don't already have implemented that. If their assembly is written in C#, adding support for that is pretty trivial by wrapping the .Net event around their special callback interface class. But first check that they do not support .Net events already in their class implementation. You can try to read the documentation about your assembly. Another quick test is to simply wire the class refnum in LabVIEW to a Register Event Callback node. If the class implements .Net events you can then click on the first terminal of the node and see a list of all events it supports. Select the one you want. There are two additional terminals for a VI refnum for the callback VI and a user parameter. Right click on the VI ref input of the register node and select Create Callback VI. See here for how this is meant to work. If no event names show up in the node drop box, the class doesn't implement .Net events and you should talk with the assembly provider about support for that.