PDA

View Full Version : [SOLVED] Issues with Arrays and DLLs



Zuccj
12-21-2017, 11:10 AM
I'm having a problem with getting arrays populated with functions that are called from a dll. A quick example is:


Private Declare Function MHL200_GetDLLVersion Lib "dll path" (ByRef pulDllVersion() As Long) As MHL200_ErrorEnum

Then, I call it as such:


Dim ulaVersion(2) As Long

ulMHL200Error = MHL200_GetDLLVersion(ulaVersion)

Each element of the array is 0, and it does this for any time I try and use an array. I can run it in C++ and it will print the correct values, so I know it isn't the dll. Is there something special needed for using arrays?

Paul_Hossler
12-21-2017, 12:46 PM
Try


Dim ulaVersion() As Long

and see

Just a thought

Zuccj
12-21-2017, 12:56 PM
Trying that gave a runtime error 9: subscript out of range on each line where I call the array, and they are:


MsgBox "dll version " & ulaversion(0) & "." & ulaversion(1)
Cells(23, 2) = ulaversion(0)

Which is kind of expected since the size isn't given.

snb
12-21-2017, 02:54 PM
This suffices:


sn = MHL200_GetDLLVersion(ulaVersion)
msgbox sn(0) & vblf & sn(1)


Do not declare any variables.

Zuccj
12-22-2017, 05:42 AM
Trying that gives a compile error: Type mismatch: array or user-defined type expected.

snb
12-22-2017, 07:06 AM
use:


sn = MHL200_GetDLLVersion
msgbox sn(0) & vblf & sn(1)

Zuccj
12-22-2017, 07:23 AM
That isn't going to work. You need to pass an argument into the functions. The return value is only for error codes.

snb
12-22-2017, 07:38 AM
I can't see the value of ulaversion......

Zuccj
12-22-2017, 07:46 AM
Here is a snippet from the dll manual which explains how that specific function should be used.
21234

snb
12-22-2017, 08:36 AM
What's the purpose of retreiving the versionnumbers ?

Probably the same result:

Sub M_snb()
for each it in ThisWorkbook.VBProject.References
msgbox it.Name & vbtag & it.minor & vbtab & it.major
next
End Sub

Zuccj
12-22-2017, 09:00 AM
There actually isn't a reason for getting the version. It is more there are other functions that access registers from an IC chip, and save those in an array. I just went with the easier example.

I ended up finding a solution though.


Private Declare Function MHL200_GetDLLVersion Lib "dll path" (ByRef pulDllVersion As Long) As MHL200_ErrorEnum
ulMHL200Error = MHL200_GetDLLVersion(dllver(LBound(dllver)))

That populated the array with the correct values.