Click to See Complete Forum and Search --> : SafeArrayTypeMismatchException when calling DLL


floydus
10-12-2006, 11:44 AM
At this line
cameraResults = objApp.executeImageSaving(camBools, brightValues, darkValues)

I get the following error.

SafeArrayTypeMismatchException was unhandled -- > Specified array was not of the expected type.

Here's how the function prototype is in VB .Net.
Function executeImageSaving(ByRef camArray As System.Array, ByRef brightArray As System.Array, ByRef darkArray As System.Array) As String
Member of: LanexDll.LanexObj._LanexObj

I'm calling a method declared like this in VB6 `
Public Function executeImageSaving(camArray() As Boolean, brightArray() As Integer, darkArray() As Integer) As String
I've never called a DLL expecting Arrays yet in VB .Net.

How should I declare the parameters to send, do I need to play with types?

I've tried 2 ways of declaring camBools, brightValues, darkValues.

'This way
Dim camBools() As Boolean
Dim brightValues() As Integer
Dim darkValues() As Integer

'and also this way.

Dim camBools As System.Array
Dim brightValues As System.Array
Dim darkValues As System.Array
Dim objApp As LanexDll.LanexObj
Dim resFonction As Integer
Dim camtxt As String
Dim cameraResults As String
Dim camBools As System.Array
Dim brightValues As System.Array
Dim darkValues As System.Array
camBools = System.Array.CreateInstance(GetType(Boolean), 16)
camBools(0) = True
camBools(1) = False.........
camBools(15) = False
brightValues = System.Array.CreateInstance(GetType(Integer), 16)
brightValues(0) = 4
brightValues(1) = 4
brightValues(15) = 4
darkValues = System.Array.CreateInstance(GetType(Integer), 16)
darkValues(0) = 4
darkValues(1) = 4
darkValues(15) = 4
objApp = New LanexDll.LanexObj()
resFonction = objApp.connect("10.1.1.201", "login", "N", "C:\Program Files\Lanex\RVC6\Rvc6.exe")
If (resFonction = 1) Then
objApp.saveStatus("c:\status.log")
End If
objApp.setUnitDatetime("08", "18", "2006", "10", "12", "15", "P")
camtxt = objApp.getCameraNames(0)
cameraResults = objApp.executeImageSaving(camBools, brightValues, darkValues)
MsgBox(camtxt)
Thanks

shstubbs
10-12-2006, 12:11 PM
In your post you indicate that the VB6 function declaration expects brightArray and darkArray as Integer, and in VB.Net they are declared as Integer as well; however, an Integer (16-bit) in VB6 is a Short (16-bit) in VB.Net. Try changing the declaration for the Integer arrays to Short or Int16 in VB.Net and see if that works. :)

floydus
10-12-2006, 12:24 PM
Thank you so much, I just spent 4 hours on this.
But I learned something usefull I guess.
Thanks again, very happy !!!!
:)