LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview 8.6 DLL to Vb.net 2008. Passing a 1D Array and returning an Array

I am using Labview 8.6 and VB.net 2008.  I need to make a Labview DLL that will accept a 1D Array from Vb.net and return an Array of Calculations

 

I can make it work using integer values and strings, but Now i need to work with an Array.

 

I have done the following.

 

NOTE* the code on the bottom will just ask Labview to accept an Array from VB and return the Array Size.

 

Vb.net

Declare Auto Function Double2DMyTry Lib "SharedLib.dll" (ByVal MyArray() As Int32) As Double

 

Result.Text = CStr(Double2DMyTry(Numbers))  'the code to call the function

 

 

labview function prototype

double Double2DMyTry(double Array[], double *Numeric)

using C calling convention

 

 

 

I get an error " attempted to read or write protected memory" when using the code above.  I would in the end like to return back an array instead of just an integer.


Thanks.

0 Kudos
Message 1 of 17
(3,865 Views)
I have seen the example that uses 2D Arrays, but that used variants.
0 Kudos
Message 2 of 17
(3,861 Views)

OK.  I have figured some things out that may help other newbies.  First, you need to set your varibles as connectors as you would when making a SubVI. Now you will be able to see your variables when buliding the dll in the project explorer.  2nd, look at the Function Prototype in the build properties, it is asking for the Array following by the length of the array ( I was just sending the Array and this was generating my error above).   Now I will try to figure out how to send back a 1D Array (I will post my solution once I get it, if there is no solution can someone please post it).

 

Thanks.

0 Kudos
Message 3 of 17
(3,854 Views)

I think I am close now but keep getting a PInvoke Restriction Error


here is my Labview Function Prototype

 

void Double2DMyTry(double Array[], double Array2[], int32_t len, int32_t len2)

 

here is my VB CODE>

 

Public Class Form1

Declare Auto Function Double2DMyTry Lib "SharedLib.dll" (ByVal MyArray() As Int32, ByVal MyArray2() As Int32, ByVal Len As Int32, ByVal Len2 As Int32)

Private Sub btnPLus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPLus.Click

Dim Numbers(4) As Integer

Numbers(0) = 1

Numbers(1) = 2

Numbers(2) = 3

Numbers(3) = 4

Dim FinalNumbers(4) As Integer

Double2DMyTry(Numbers, FinalNumbers, UBound(Numbers), UBound(FinalNumbers))

result.Text = FinalNumbers(0) + FinalNumbers(1) + FinalNumbers(2) + FinalNumbers(3)

End Sub

End Class

0 Kudos
Message 4 of 17
(3,849 Views)

Hi Diopsys,

 

Does the following Discussion Forum help:

http://forums.ni.com/ni/board/message?board.id=170&requireLogin=False&thread.id=162333

 

 Flash

National Instruments
Applications Engineer
0 Kudos
Message 5 of 17
(3,827 Views)
i looked at the thread mentioned above, but it didnt help.  I needed the correct VB syntax.  I belive the issue is on the VB side.
0 Kudos
Message 6 of 17
(3,816 Views)
I had attached my code ( VB and my labview program)  if someone would like to look at it.
0 Kudos
Message 7 of 17
(3,810 Views)

Hi DiopsysP,

 

So you saw this:

http://zone.ni.com/devzone/cda/epd/p/id/4504

 

Why dont you want to use variants?

 

Flash

National Instruments
Applications Engineer
0 Kudos
Message 8 of 17
(3,801 Views)

I have tried to make that example work for me for hours.  I am using Labview 8.6 and VS 2008.  I have recomplied everything again but I get " attempted to read or write protected memory" errors.

 

I dont mind using variants, anything that works.  

0 Kudos
Message 9 of 17
(3,794 Views)

Hi DiopsysP,

 

I just tried the example found on 

http://zone.ni.com/devzone/cda/epd/p/id/4504

and it worked.

 

Have you tried it?

 

Flash

National Instruments
Applications Engineer
0 Kudos
Message 10 of 17
(3,778 Views)