07-26-2007 04:05 PM
Private
Declare Sub Getsw Lib "..\Labview\DemoSwCtrl.dll" Alias "Getsw" (ByVal swin As String, ByVal swipa As String, ByRef ecode As Int32, ByVal errmsg As Char, ByVal swout As Char, ByVal lenerr As Int32, ByVal lenver As Int32)And I call the function with the following:
Dim ipa As String = TxtBxIpa.Text
Dim errcode As Int32
Dim lerr As Int32 = 100
Dim lout As Int32 = 100
Dim errtxt As String
errtxt = Space(100)
Dim outtxt As String
outtxt = Space(100)
Dim intxt As String = TxtBxStrIn.Text
Getsw(intxt, ipa, errcode, errtxt, outtxt, lerr, lout)
TxtBxErrCode.Text = errcode.ToString
TxtBxStrOut.Text = outtxt
TxtBxErrMsg.Text = errtxt
In the above code the errtxt = Space(100) and outtxt = Space(100) result in an error being generated when I run my vb executable. The error is:
"An unhandled exception of type 'System.NullReferenceException' occurred in DLL Demo.exe Additional information: Object reference not set to an instance of an object."
If I comment out these two lines the vb code runs without error and returns the proper numeric errcode, but the string indicators for the returned values in errtxt and outtxt are empty.
I have developed my DLL using "char", "PStr" and "LStrHandle" and can't get any of these types to work.
The DLL works fine when called in labview (using "char"). What am I doing wrong in VB.net?
There are so many variables and so many permutations that can be tried using all the variables.....
Ed
07-27-2007 05:59 PM
07-31-2007 11:50 AM
07-31-2007 11:54 AM
Here is another way I made it work with StringBuilder. This is the same project as the other one, just modified to use StringBuilder. I would not recommend having both on your computer at the same time.
Let me know if this helps!
08-01-2007 09:03 AM
08-02-2007 10:26 AM
07-15-2010 03:26 AM
how come all the vb.net to labview.dll samples/examples result in the same error and wont continue??
"Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang."
trried a dozen of them now and all result in the same error? what am i missing?
Im on dotnet 2.0 with vs2005 by the way
07-15-2010 04:12 PM
Hi Matma,
Here's KnowledgeBase Article that deals with that exact issue:
KnowledgeBase 3ZJ8MC45: Error with LoaderLock Managed Debugging Assitant (MDA) when Calling a DLL.
This is an issue specific to .NET 2.0.
Hope this helps!
06-19-2015 04:47 PM
Hi Daniel,
Thank you so much for providing this example. It is complete, thorough and clear.
This gives me better understanding how the string work in Labview.
Have a great day,
Mie Mie