Consulting

Results 1 to 11 of 11

Thread: Issues with Arrays and DLLs

  1. #1
    VBAX Regular
    Joined
    Jun 2017
    Posts
    23
    Location

    Issues with Arrays and DLLs

    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?

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Try

    Dim ulaVersion() As Long
    and see

    Just a thought
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Jun 2017
    Posts
    23
    Location
    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.

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    This suffices:

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

    Do not declare any variables.

  5. #5
    VBAX Regular
    Joined
    Jun 2017
    Posts
    23
    Location
    Trying that gives a compile error: Type mismatch: array or user-defined type expected.

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    use:

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

  7. #7
    VBAX Regular
    Joined
    Jun 2017
    Posts
    23
    Location
    That isn't going to work. You need to pass an argument into the functions. The return value is only for error codes.

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    I can't see the value of ulaversion......

  9. #9
    VBAX Regular
    Joined
    Jun 2017
    Posts
    23
    Location
    Here is a snippet from the dll manual which explains how that specific function should be used.
    def.jpg

  10. #10
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    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

  11. #11
    VBAX Regular
    Joined
    Jun 2017
    Posts
    23
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •