From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

to access function or properties in sealed singleton objects(classes) in .NET

Solved!
Go to solution

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 

0 Kudos
Message 1 of 7
(4,598 Views)

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.

 

Joey S.
Senior Product Manager, Software
National Instruments
0 Kudos
Message 2 of 7
(4,579 Views)
Solution
Accepted by topic author bestchun1

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:

Screen Shot 2013-03-08 at 4.13.27 PM.png

 

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.

 

Screen Shot 2013-03-08 at 4.16.27 PM.png

 

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)

 

Screen Shot 2013-03-08 at 4.19.25 PM.png

 

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:

 

Screen Shot 2013-03-08 at 4.21.15 PM.png

 

Hope this helps.

 

SimonH

National Instruments

 

Message 3 of 7
(4,563 Views)

Yes, I fixed it. Thank you very much

0 Kudos
Message 4 of 7
(4,525 Views)

@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.

0 Kudos
Message 5 of 7
(4,452 Views)

Hi,

is it needed that the reference is closedafter execution with Connectivity >> .NET >> Close Reference after the execution?

Thx

0 Kudos
Message 6 of 7
(4,422 Views)

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.

0 Kudos
Message 7 of 7
(4,405 Views)