I have a .NET class library that I wrote in C++. "public ref class MyClass" defines a method "MyMethod" that takes two System::Int32 parameters.
Here is MyClass first then my question:
namespace MyNetAssembly {
public ref class MyClassThatDoesStuff
{
public:
MyClassThatDoesStuff();
void MyMethod(System::Int32^ number1, System::Int32^ number2);
property System::Int32 MyProperty{
int get (){
return *_result;
}
void set(System::Int32 value){
}
}
private:
int^ _result;
};
}
Her开发者_如何学Pythone is the cpp code:
MyNetAssembly::MyClassThatDoesStuff::MyClassThatDoesStuff()
{
*_result = 0;
}
void MyNetAssembly::MyClassThatDoesStuff::MyMethod(System::Int32^ number1, System::Int32^ number2)
{
*_result =(*number1 + *number2) * 100;
}
When I load this assembly from LabView 8.5 using "Constructor Node" vi. Then, I try to invoke MyMethod() using an "Invoke Method" vi, I get the parameters to the method to be of "ValuteType" and not "Int32" as I expect to use directly with LabView constants and controls. Rather, when I create a constant by right clicking on the connector for the parameter, I get ".NET Object"!
Please, How can I get LabView to recognize parameter types?
Note: I tried to change parameters from System::Int32^ number1
to System::Int32 number1
. That did not help either.
I think I figured it out! Apparently, there is something funny happens within the vi file itself. If there is a .NET Constructor Node with an assembly defined, then rebuilding the assembly in Visual Studio and updating the Constructor Node does not have an effect over imported method signatures. Therefore, MyMethod(System::Int32 number1, System::Int32 number2, System::String^ str)
was no were to be seen.
So, what worked for me is the following:
- I deleted *Constructor Node* and *Invoke Node* from vi, then saved.
- To pass integer values to
MyMethode
here is the method definition that worked for me:MyMethod(System::Int32 number1, System::Int32 number2, System::String^ str)
It can be confusing when LabView have you under the impression that it has completely updated itself when you rebuild your .NET Assembly.
Thanks to everyone who helped. I hope my answer is helpful to anyone else who is working with .NET and LabView.
精彩评论