06-28-2010 11:03 AM
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.
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.
06-28-2010 07:22 PM
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.
06-29-2010 11:50 AM
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?
06-29-2010 02:09 PM
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.
07-01-2010 08:32 AM
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.
07-01-2010 09:45 AM
Then pass in a non empty (any) string. LabVIEW can't pass in a NULL reference for a string that contains anything.
07-08-2010 10:48 AM
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. 
07-08-2010 03:32 PM - edited 07-08-2010 03:33 PM
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.
07-08-2010 04:16 PM
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?
07-10-2010 12:58 AM
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.