Specified array was not of the expected type. Calling VB6 DLL

I Get the following error when running my code.

 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



Answer this question

Specified array was not of the expected type. Calling VB6 DLL

  • dseifert

    I'd go with Dman1's suggestion - the type integer in vb6 is a 16 bit integer, and the type long is a 32 bit integer. In VB 2002 and later, the type integer is a 32 bit integer, and the type long is a 64 bit integer. A type short, which is a 16 bit integer is also defined, so a vb6 integer ==> vb 2002+ short, and a vb6 long ==> vb 2002+ integer.

  • GoDaddy

    What error are you getting

    Take a look at whether you need to pass byref or byval...default for VB6 is byref...default for .NET is byVal...

    also....the integer precision is different in VB6 and .NET...



  • tiffeyneohelp

    Instead of declaring them as integer arrays...try declaring them as Int16 arrays!

  • Anton Papst

    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


  • hipswich

    I've declared them as Short, and it just went through.

    Thanks


  • Specified array was not of the expected type. Calling VB6 DLL