Results 1 to 3 of 3

Thread: Passing an array pointer to a DLL

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Post

    How do I pass a pointer from an array to a DLL?

    Heres the DLL function declaration:

    Declare Function CANPC_send_data Lib "cancard.dll" Alias "_CANPC_send_data@16" (ByVal ident%, ByVal Xtd%, ByVal DataLength%, pdata As Byte) As Integer

    pdata is a "pointer to the address field of the data"

    Heres a snippet of the function were I call the DLL

    Public Sub TxSI(ByVal PacketType, ByVal Node_ident As Byte, ByVal DataLength As Byte, ByVal Instruction As Byte, ByVal Data2 As Byte, ByVal Data3 As Byte)

    Dim pdata(3) As Byte
    Dim ident As Integer
    Dim err As Byte

    'pdata(0) = Instruction
    'pdata(1) = Data2
    'pdata(2) = Data3

    pdata(0) = 1
    pdata(1) = 2
    pdata(2) = 3

    ident = PacketType * 128 ' align packet type with MSB
    ident = ident Or Node_ident ' add node ident

    If gvStatus.init = True Then
    err = CANPC_send_data(ident, 0, DataLength, pdata)

    .....

    The DLL demands a pointer to the array. I thought passing the array (as above) into a Byref would do this, however the above code causes a vb error.

    I have tried changing the declaration to ...pdata (). This compiles ok, but the array data doesnt get passed correctly into the DLL function.

    I`ve also tried using VarPtr, but this returns a long, the DLL demands a byte?? How can this work?
    Any ideas?

    [This message has been edited by Rick H (edited 02-11-2000).]

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Post

    It works ok now, for those of you that are interested I had to pass the first element of the array pdata(0), and have the declaration as byref pdata as byte


  3. #3
    Junior Member
    Join Date
    Jan 2000
    Location
    Edmonton,AB, Canada
    Posts
    30

    Post

    I highly recommend the following book from Dan Appleman; "Visual Basic Programmer's Guide to the Win32 API". It not only is an excellent book with the Win32 but it also teaches one about VB and dll's in general.



    ------------------
    David L. Baudais
    Systems Analyst


Posting Permissions

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



Click Here to Expand Forum to Full Width