|
-
Feb 10th, 2000, 05:59 PM
#1
Thread Starter
Hyperactive Member
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).]
-
Feb 10th, 2000, 07:17 PM
#2
Thread Starter
Hyperactive Member
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
-
Feb 10th, 2000, 08:06 PM
#3
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|