LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a reference of a string into a VB .NET function

I need to call an external VB .NET function which pass one of the parameters by reference. Here is the description of the fuction:

 

     GetName (Integer Pos, String& Name) As Integer

 

When called within LabVIEW, here is what it looks like. 

17571iFF3E6E0D481B1906

 

For the string name, it's asking for a reference. How do I pass a string reference in this case? The way I did it does not work, keeps sending back a system error which makes sense, since the labview string does not contain a reference to itself. 

0 Kudos
Message 1 of 12
(6,817 Views)

You should check your system error again. Because LabVIEW seems to treat that variable quite fine as it is both an input and output. Maybe you need to allocate an actual string to pass to the input and not just an empty string.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 12
(6,804 Views)

this is the error message I got after running the VI again. This time I put an actual string 'Empty' into the Control, but still VI errored out. 

 

I searched this error 1172 System.ArgumentNullException, it arises from the fact that the object is not instantiated, in this case, 'Name' string. Don't really know what it means, but how to instantiate a string in LabVIEW?

 

17675i92BAB06980204210

0 Kudos
Message 3 of 12
(6,788 Views)

Well the name parameter is both an input and an output and likely it requires it to have a meaningful string value (and seems to consider an empty string not to be a meaningful value). Seems the method passes this name parameter as key value to another .Net method who then causes an exception. Pass in a name that is valid for this method.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 12
(6,782 Views)

I think what the error said was that the parameter passed in was a null reference, it's expecting a valid reference to a string. This is the question I asked in the first post, how can LabVIEW pass a string reference. 

 

and the function is not expecting anything meaningful; what matters is the return --- with a valid reference passed in, the function can manipulate the string and returns a value. 

0 Kudos
Message 5 of 12
(6,737 Views)

Then pass in a non empty (any) string. LabVIEW can't pass in a NULL reference for a string that contains anything.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 6 of 12
(6,731 Views)

Problem solved. 

 

The way to solve the passing_String_ByRef is to pass the first char in the string, as shown in the following image. 

0 Kudos
Message 7 of 12
(6,693 Views)

Interesting! But I miss the connection between the first problem with a .Net or Active X node and the Call Library Node here. Also you do not pass a reference to the pointer in the Call Library node but simply the C string pointer.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 12
(6,684 Views)

Yes, that's true, it's much simpler in the Call Library node; but with a .NET node, where it is not possible to assign a pointer, that's the way to pass a string ByRef. 

 

Then it raises another question---what if I wanted to pass a primitive type like an Integer ByRef to a .NET node? A string can be treated as an array, but an Integer is simply a single element. Any clue?

0 Kudos
Message 9 of 12
(6,674 Views)

You are not passing a string byRef here. You are passing the string pointer which is the only way a string can be passed to a function also in .Net and ActiveX. Another possibility would be a pointer to the string pointer (which is more like a string passed byRef) but that is not possible in the Call Library Node, since for such string pointers it is not clear if the caller or callee is allocating the memory and if the component developer has decided that the function is doing it this is absolutely incompatible with the LabVIEW memory management.

 

How the parameters are passed in ActiveX and .Net is only determined by the Type Library of that component and you have no possibility to change that manually. If the Type Library is correct, LabVIEW will do the correct thing. If the type library is wrong there is no way to force LabVIEW to do the right thing.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 10 of 12
(6,657 Views)