03-07-2013 02:04 PM
I have a dll developed in vc 2010 with .NET Framework 4 in Microsoft Visual C# 2010. I am trying to access .NET Objects using .NET Constructor. And I can assess some of objects(classes) successfully.
But some of classes(objects) are fully sealed and no constructor is available. In C#, I could access functions of such class using Instance. For example I would like access function, F, of class A, and I could use "A.instance.F"... Is there similar tool in labview 2012?
Thanks a lot.
Best,
Michael
Solved! Go to Solution.
03-08-2013 03:24 PM
Hi Michael,
Good question! I am not sure exactly what you mean by sealed classes. To clarify, you are using the .NET constructor node, but some classes are not appearing as options?
Another option would be to create your DLL as Win32 DLL and call it in LabVIEW using a Call Library Function Node.
This Help document gives a good overview of our .NET functionality.
03-08-2013 04:33 PM
Michael,
When you say "sealed" do you mean "static"? Sealed means you can't inherit from that class but you should be able to create instances using a constructor. Static means you can't instantiate a new instance of that class (i.e. there is no constructor). Static classes are also sealed.
For example, System.Math in mscorlib.dll is static. It has no constructor:
However I can still use it's functions if I use a .NET constant rather than a constructor. I hope there's an easier to find way to do this but I always just right click on the output of the contructor node and select Create>>Constant.
Then right click on your new constant and select Select .NET Class>>Browse and go find your assembly and object (in our case System.Math in mscorlib)
Now you can wire this reference to an invoke node to use the functions within the static class. I also like to label the reference with the name of the class to make the code easier to read, like so:
Hope this helps.
SimonH
National Instruments
03-14-2013 03:21 PM
Yes, I fixed it. Thank you very much
05-17-2013 12:40 PM
@SimonH wrote:
However I can still use it's functions if I use a .NET constant rather than a constructor. I hope there's an easier to find way to do this but I always just right click on the output of the contructor node and select Create>>Constant.
Since you mentioned wanting an easier way to do this: drop an invoke or property node on the block diagram, right-click, Select Class -> .NET -> Browse, choose the appropriate assembly. The .NET class constant is not needed. You can still wire the reference output to another node even though there's nothing connected to the reference input.
05-21-2013 03:22 AM
Hi,
is it needed that the reference is closedafter execution with Connectivity >> .NET >> Close Reference after the execution?
Thx
05-21-2013 01:29 PM
It is always a good idea to close .NET references when you are done with them. I'm not certain if it is necessary in this case but it won't hurt to close it.