LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to return a String from a LabView DLL to .NET?

How Do I receive (output) Strings from a LabView dll inside a .NET language?
 
Background:
 
I have a very simple VI (for test purpose) which just returns a string as output (see attached vi.jpg).
Then I have created a LabView dll (helloworld.dll) with the help of the Application Builder.
I have used  "C-String Pointer" as parameter type for the dll function:
 
void HelloWorld(char OutputString[], long LNge)
 
 (see vi-prototype.jpg).
 
No I would like to receive this string from a VB.NET application where I have imported the
generated LabView dll:
 
<DllImport("C:\outgoing\LabView\helloworld.dll", CallingConvention:=CallingConvention.StdCall)> _
Public Shared Sub HelloWorld(ByRef OutputString() as Char, ByVal LNge as Long)
End Sub
 
But when I call inside .NET:
 
Dim OutputString(100) as Char
Dim LNge as Long = 100
HelloWorld(OutputString, LNge)
 
I get a "Method's type signature is not Interop compatible." exception.
Tried also with Pointer to String-Handle/ Pascal-String-Pointer and IntPtr at .NET but without success?
 
(If I have a VI with a String as Input it is working very well if I define the InputString as InputString() as Char, Integers are also
not a problem, but no success with String as LabView dll output, also
does not help much.)
 
 
Any hint welcome + thanks in advance,
 
Markus
 
 
Used LabView version: 8.20
Download All
0 Kudos
Message 1 of 6
(4,480 Views)
Hello Markus,

First of all I saw this line:
<DllImport("C:\outgoing\LabView\helloworld.dll", CallingConvention:=CallingConvention.StdCall)> _

The calling convention in your prototype attachment is not set to standard, but to C.

Second, if strings don't work, try using arrays of Uint8 instead. Which is nothing other than an array of chars. In this way you have nothing to do with different ways of internally storing strings, which is different for different programming languages.

Kind regards,

André
Regards,
André (CLA, CLED)
0 Kudos
Message 2 of 6
(4,465 Views)

Thanks Andrè  for the Reply.

But still no success.

I have changed the output string to an array of Byte. (see vi2.jpg)

The VI-ProtoType is now:

void HelloWorld(unsigned char StringArray[], long LNge)  (see vi-prototype2.jpg)

and the .NET Declaration is changed to:

<DllImport("C:\outgoing\LabView\helloworld.dll", CallingConvention:=CallingConvention.Cdecl)> _
Public Shared Sub HelloWorld(ByRef StringArray() as Byte, ByRef LNge as Long)
End Sub
 
But I still get an "Method's type signature is not Interop compatible." exception. I also tried to change declaration to
 
Public Shared Sub HelloWorld(ByRef StringArray() as Char, ByRef LNge as Long)
 
(but LabView uses unsigned Char = Byte)
 
Do you have some example lines of Code (C# or VB.NET)?
 

Thanks again,

Markus

 

Download All
0 Kudos
Message 3 of 6
(4,462 Views)
Hello,


Where do you declare the value of "LNge"?

If you search for
"Method's type signature is not Interop compatible." in a search engine, you will find hints to what the problem might be.

I found this "<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconCallingWindowsAPIs.asp>
vaconCallingWindowsAPIs.asp</a>"

Regards,

André

Message Edited by andre.buurman@carya on 07-25-2007 09:20 AM

Regards,
André (CLA, CLED)
0 Kudos
Message 4 of 6
(4,457 Views)

I have declared LNge as Long before I call the HelloWorld function.

And LNge does return 11 which is the correct length of the "Hello World" string. But the string itself

I am not able to receive.

 

Still help needed.

Is nobody here who can receive a String from a LabView dll inside a .NET environment???

 

Regards,

Markus

 

0 Kudos
Message 5 of 6
(4,452 Views)
The problem, I believe, is that you are not passing the correct types for P/Invoke marshaling. .NET defines the StringBuffer class as the marshal type for handling c strings.

I often use pinvoke.net as a great source for examples on how to marshal all sorts of data types. For an example on strings such as what you are trying to do, take a look at http://pinvoke.net/default.aspx/user32/GetWindowText.html
0 Kudos
Message 6 of 6
(4,373 Views)